Wednesday, August 19, 2009

Checking a CheckBox in DatagridViewCheckboxColumn from code

I had a situation with a DatagridViewCheckboxColumn where I had to check a checkbox based on some conditions when the user initiates a click. Normally you would do that by setting the value of the column to true.
ex: gridView[e.ColumnIndex, e.RowIndex].Value = true;

But this code wans't updating the UI untill I clicked elsewhere on the grid or any other control. I tried using Invalidate, refresh etc. and nothing worked. Turns out as long as the current cell for the grid is assigned the UI will not get updated. So I got the whole thing to working by setting the CurrentCell to null.
Ex: gridView.CurrentCell = null;

No comments:

Post a Comment