How can I get this to update the underlying bound data?
with a check box column and a text column (more columns will follow, but this is the minimal working example that I'm trying to get working). Are you setting any other properties on your Data Grid View?
When I run this code, the checkbox columns appears, but I can't check the boxes. I just tried running this code and the boxes appear checked, and can be cleared using the mouse as normal.
(Note that my code is in VB, but I think the same concept would apply to other .
NET languages) I then realized that it was because the underlying value of the cell isnt changed until it loses focus.
(Ex: if you shift it to a button the user might be surprised when they press enter and a random button activates.) Depending on what else is in your DGV, you may want to check the column index of the event so that you are only doing this for the checkbox columns.
All of the other columns in my DGV are read only anyways, so it didnt matter in my case.
If the code in question was contained in a button, the focus would already be shifted away from the DGV to the button, so this wouldn't be an issue.
In my case, the code was activated by a timer - meaning that the DGV cell in question wouldn't necissarily lose focus before the timer fired.
And now I have a problem: When I click once on Checkbox it changes but only visualy, in code its value is still set to false.
But if I click on Checkbox and then anywhere else on my datagridview (or change its value manually in code on true) it changes its value on true.
I think DGVs always behave like this, but it can be easy to forget.