DataGridView.CellValueChanged没有在绑定的DataGridView上触发 [英] DataGridView.CellValueChanged not firing on bound DataGridView
问题描述
当我在DataGridView绑定到DataTable中以编程方式更改值时,相应的CellValueChanged事件不会触发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. 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
,并期望 DataGridView
的事件被触发?
我建议您以编程方式更改单元格值:
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;
此外,您必须调用 DataGridView.CommitEdit()
将值提交到 DataTable
。这应该触发 CellValueChanged
事件。
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
这篇关于DataGridView.CellValueChanged没有在绑定的DataGridView上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!