DataGridView.CellValueChanged没有在绑定的DataGridView上触发

当我在我的DataGridView绑定的DataTable中以编程方式更改值时,不会为DataGridView触发相应的CellValueChanged事件。 当DataTable填充数据而不迭代每一行并检查每个值时,我正在尝试根据单元格值更改单元格的背景颜色。

您是直接更改DataTable并期望触发DataGridView的事件? 我建议你以编程方式更改单元格值:

 DataGridView[ColumnIndex, RowIndex].Value = NewValue; 

此外,您必须调用DataGridView.CommitEdit()将值提交到DataTable 。 这应该触发CellValueChanged事件。

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

应在RowPrePaint-Event中更改单元格背景颜色,如果在值更改后重新绘制行,则会触发此操作。