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
2010-04-05 18:41:33
Yes I expect it to fire. The value displayed in the cell is changing.
Wesley
2010-04-05 18:48:00
CellValueChanged event only fires when a new value is pushed from the DGV to the DT. Not other way round.
Vivek
2010-04-05 18:52:07
I don't mind the down votes, but a reason will certainly help.
Vivek
2010-04-05 18:58:58
I'm not able to down vote yet.
Wesley
2010-04-05 19:04:52
+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
2010-07-08 08:34:31