簡體   English   中英

DataGridView.CellValueChanged沒有在綁定的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM