[英]DataGridView.CellValueChanged not firing on bound DataGridView
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. 当我在我的DataGridView绑定的DataTable中以编程方式更改值时,不会为DataGridView触发相应的CellValueChanged事件。 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.
当DataTable填充数据而不迭代每一行并检查每个值时,我正在尝试根据单元格值更改单元格的背景颜色。
You are changing the DataTable
directly and expect DataGridView
's event to be fired? 您正在直接更改
DataTable
并期望触发DataGridView
的事件? 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
. 此外,您必须调用
DataGridView.CommitEdit()
将值提交给DataTable
。 This should trigger the CellValueChanged
event. 这应该触发
CellValueChanged
事件。
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx
应在RowPrePaint-Event中更改单元格背景颜色,如果在值更改后重新绘制行,则会触发此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.