الخميس، 26 ديسمبر 2013

DataGridViewCheckBoxCell click handling issue

I created a DataGridView control where the first column is a checkbox. When I click inside the check box, the code correctly executes. HOWEVER, when the click occurs in the cell but not in the checkbox, the code correctly handles the state of the checkbox but does not update the checkbox itself, so it remains in the state it was before the click.

How do I correct this?

private void myDataGrid_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) return; //check if row index is not selected DataGridViewCheckBoxCell ch1 = new DataGridViewCheckBoxCell(); ch1 = (DataGridViewCheckBoxCell)myDataGrid.Rows[e.RowIndex].Cells[0]; if (ch1.Value == null) ch1.Value = false; switch (ch1.Value.ToString()) { case "False": ch1.Value = true; break; case "True": ch1.Value = false; break; } //BUT doesn't seem to matter what I do with ch1.Value. Inside the checkbox all is OK but //outside, no. }

If I click in another cell on the row, the check box is handled correctly. ONLY when I click in the check box cell but NOT in the checkbox itself. Thanks RON


View the original article here

ليست هناك تعليقات:

إرسال تعليق