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 );

One Reply to “Hosting a Custom Control in a DataGridView”

Leave a Reply

Your email address will not be published. Required fields are marked *