Tutorial :DataGridView.CellValueChanged not firing on bound DataGridView



Question:

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.


Solution:1

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.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx


Solution:2

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
Previous
Next Post »