Hi,
I'm having a problem when trying to convert an DataGridViewCell at runtime. from what i can see this is a knowen issue but i cant get the workaround to work for me. this is what i have
Ok so on Row leave i want to set everyting back to textboxcellsCode:public Form1() { InitializeComponent(); Main.Columns.Add("Period", typeof(int)); Main.Columns.Add("Type", typeof(int)); Main.Rows.Add(1, 1); Main.Rows.Add(1, 2); Main.Rows.Add(1, 3); Main.Rows.Add(2, 1); Main.Rows.Add(2, 2); Main.Rows.Add(2, 3); Periods.Columns.Add("Code", typeof(int)); Periods.Columns.Add("Desc", typeof(String)); Periods.Rows.Add(1, "Jan"); Periods.Rows.Add(2, "Feb"); Types.Columns.Add("Code", typeof(int)); Types.Columns.Add("Desc", typeof(String)); Types.Rows.Add(1, "Int"); Types.Rows.Add(2, "String"); Types.Rows.Add(3, "Float"); dgv.DataSource = Main; dgv.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dgv_DataBindingComplete); } void dgv_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { dgv.DataBindingComplete -= new DataGridViewBindingCompleteEventHandler(dgv_DataBindingComplete); dgv.RowEnter += new DataGridViewCellEventHandler(dgv_RowEnter); dgv.RowLeave += new DataGridViewCellEventHandler(dgv_RowLeave); } void dgv_RowLeave(object sender, DataGridViewCellEventArgs e) { foreach (DataGridViewColumn c in this.dgv.Columns) { this.dgv[c.Index, e.RowIndex] = new DataGridViewTextBoxCell(); } } void dgv_RowEnter(object sender, DataGridViewCellEventArgs e) { foreach (DataGridViewColumn c in this.dgv.Columns) { this.dgv[c.Index, e.RowIndex] = new DataGridViewComboBoxCell(); switch (c.Index) { case 0: { ((DataGridViewComboBoxCell)this.dgv[c.Index, e.RowIndex]).DataSource = Periods; ((DataGridViewComboBoxCell)this.dgv[c.Index, e.RowIndex]).ValueMember = "Code"; ((DataGridViewComboBoxCell)this.dgv[c.Index, e.RowIndex]).DisplayMember = "Desc"; break; } case 1: { ((DataGridViewComboBoxCell)this.dgv[c.Index, e.RowIndex]).DataSource = Types; ((DataGridViewComboBoxCell)this.dgv[c.Index, e.RowIndex]).ValueMember = "Code"; ((DataGridViewComboBoxCell)this.dgv[c.Index, e.RowIndex]).DisplayMember = "Desc"; break; } } } }
on Row Enter i want to set the current row to ComboBoxCells
this works ok unless i select Cell (0,0) / (1,1) then select another cell i get this error on the RowLeave "Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function"
Can anyone help please![]()


Reply With Quote
Bookmarks