![](/img/trans.png)
[英]DataGridView.CellValueChanged not firing for data-bound DataGridView
[英]DataGridView.CellValueChanged not firing on bound DataGridView
當我在我的DataGridView綁定的DataTable中以編程方式更改值時,不會為DataGridView觸發相應的CellValueChanged事件。 當DataTable填充數據而不迭代每一行並檢查每個值時,我正在嘗試根據單元格值更改單元格的背景顏色。
您正在直接更改DataTable
並期望觸發DataGridView
的事件? 我建議您以編程方式更改單元格值:
DataGridView[ColumnIndex, RowIndex].Value = NewValue;
此外,您必須調用DataGridView.CommitEdit()
將值提交給DataTable
。 這應該觸發CellValueChanged
事件。
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx
應在RowPrePaint-Event中更改單元格背景顏色,如果在值更改后重新繪制行,則會觸發此操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.