private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Col1");
dt.Columns.Add("Col2);
for (int j = 0; j < 10; j++)
{
dt.Rows.Add(new string[] { j.ToString(), "aaa"});
}
dataGridView1.DataSource = dt;
}
Here I have created one datatable and bind it to data grid view. I want update column = 1 and row= 1 cell as a combobox cell when it clicked so i used following events.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1 && e.RowIndex == 1)
{
object value = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
ComboBoxCell = new DataGridViewComboBoxCell();
ComboBoxCell.Items.AddRange(Values);
this.dataGridView1[1, 1] = ComboBoxCell;
this.dataGridView1[1, 1].Value = Values[0];
TextBoxCell = null;
}
}
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1 && e.RowIndex == 1)
{
TextBoxCell = new DataGridViewTextBoxCell();
this.dataGridView1[1, 1] = TextBoxCell;
ComboBoxCell = null;
}
}
but here in cell_leave event it raised exceptions
"Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function"
Please help me to resolve this.
I tried to add combo box on column=1 row = 2 then its working fine but only when there is a same column and same row problem occurs