DataGridView.CellValueChanged not firing on bound DataGridView

后端 未结 2 1426
暗喜
暗喜 2021-01-21 05:39

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

相关标签:
2条回答
  • 2021-01-21 05:52

    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

    0 讨论(0)
  • 2021-01-21 06:04

    Changing the cells background color should be done in the RowPrePaint-Event, this will be fired if the row is repainted, after the value change.

    0 讨论(0)
提交回复
热议问题