当我在一个数据绑定到DataGridView的DataTable中编程更改值时,适当的CellValueChanged事件不会触发DataGridView。我试图在填充数据表时基于单元格值更改单元格的背景颜色,而不是迭代每一行并检查每个值。
当我在一个数据绑定到DataGridView的DataTable中编程更改值时,适当的CellValueChanged事件不会触发DataGridView。我试图在填充数据表时基于单元格值更改单元格的背景颜色,而不是迭代每一行并检查每个值。
DataTable
并期望触发 DataGridView
的事件吗?
我建议你以编程方式更改单元格的值,如下所示:DataGridView[ColumnIndex, RowIndex].Value = NewValue;
DataGridView.CommitEdit()
将值提交到DataTable
。这应该会触发CellValueChanged
事件。更改单元格的背景颜色应该在RowPrePaint事件中完成,这将在行重新绘制后触发,值更改后。