简体   繁体   中英

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. 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM