views:

443

answers:

2

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.

+1  A: 

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

Vivek
Yes I expect it to fire. The value displayed in the cell is changing.
Wesley
CellValueChanged event only fires when a new value is pushed from the DGV to the DT. Not other way round.
Vivek
I don't mind the down votes, but a reason will certainly help.
Vivek
I'm not able to down vote yet.
Wesley
+1  A: 

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.

BeowulfOF