Tutorial :DataGridView.CellValueChanged not firing on bound DataGridView


When I change a value programatically in a DataTable that my DataGridView is bound to, the appropriate CellValueChanged event is not firing for the DataGridView. I'm trying to change a cell's background color based on cell value when the DataTable is filled with data without iterating through every row and checking each value.


You are changing the DataTable directly and expect DataGridView's event to be fired? I suggest that you change the cell value programatically as:

DataGridView[ColumnIndex, RowIndex].Value = NewValue;  

Additionally you will have to Call DataGridView.CommitEdit() to commit the values to the DataTable. This should trigger the CellValueChanged event.



Changing the cells background color should be done in the RowPrePaint-Event, this will be fired if the row is repainted, after the value change.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »