Hosting a Custom Control in a DataGridView

Another boring .NET post. Sorry – this is more for my own book keeping than anything else (and because it took me ages to find the solution online).

Okay, we’re creating a custom cell for a DataGridView control in Windows Forms. The custom cell hosts a custom control that implements the IDataGridViewEditingControl interface, allowing it to return data in a manner that the DataGridView expects. No matter what I tried, I couldn’t get the DataGridView to update with the new value from the custom control.

The missing piece of the puzzle? NotifyCurrentCellDirty. Whenever the value in the control changes, you must set NotifyCurrentCellDirty to true. Something like this will do the trick:

this.EditingControlDataGridView.NotifyCurrentCellDirty( true );
Categorized as Uncategorized Tagged , ,

1 comment

Leave a Reply to additnow Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.