I'm working on an application with a DataGridView
bound to a list of entities. The last column is a DataGridViewCheckBoxColumn
that toggles between 0 and 1 to set the Status
property of the entity. I handle the CellContentClick
event of the DataGridView
, and if the cell is a DataGridViewCheckBoxCell
, I call DataGridView.CommitEdit(DataGridViewErrorContexts.CurrentCellChanged)
.
I'm also handling the CellValueChanged
event, so that when the status changes, I can set the CreatedDate
property to either DateTime.Now
or an instance of Nullable<DateTime>
, based on the value of the cell.
When clicking a checkbox like a normal person, everything works just fine, and as expected. The corresponding DataGridViewCell
for CreatedDate
updates instantly.
If I click the checkbox quickly twice in a row, however, the CreatedDate
in the grid ends up displaying the appropriate value for the first of those two clicks. I'm not talking about double-click speed, either--it is at a much more moderate speed.
Now, the good thing is that the actual underlying data is being changed appropriately. So I know that the appropriate events are firing and that the handlers are being hit. But for whatever reason, the DataGridView
is not getting the update. I've tried manually calling Refresh()
, disabling the whole form after the click and reenabling it after the entity is saved (in this case, the second click still registered, because the time between disable and reenable ends up being quite short), and nothing works.
Ideas?