1

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?

Brian Warshaw
  • 22,657
  • 9
  • 53
  • 72
  • Not sure what is causing this, but does your binded entities implement `INotifyPropertyChanged`, and do you raise the `PropertyChanged` event in the entity setters? That is often the surest way that the `datagridview` will get the message that a value has changed. – Tekito Nov 23 '14 at 04:27

0 Answers0