[英]DataGridView.CellValueChanged not firing on bound DataGridView
[英]DataGridView.CellValueChanged not firing for data-bound DataGridView
尽管之前有很多类似的问题被问到,但是我没有找到合适的答案:(。例如, 类似的问题
我的DataGridView.Cellvalues
会根据数据绑定源以编程方式进行更改。 我想跟踪某些列的总和,但是DataGridView.CellValueChanged
事件仅在单元格具有焦点时才适用(不是它以编程方式更改)。 由于性能原因,我不想使用RowPrePaint
Event或CellPainting
事件。
有什么合适的事件或方法吗?
我有一个类似的问题,并使用DataBindingComplete事件解决了它。
仅适用于某些列,这应该对您来说效果很好,因为我相信在数据绑定操作完成后才调用一次。
您将需要根据需要在网格中进行自己的迭代,因为DataGridViewBindingCompleteEventArgs显然没有RowIndex和ColumnIndex属性,但是您可以执行以下操作:
private void DataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
var senderGrid = (DataGridView)sender;
foreach (DataGridViewRow row in senderGrid.Rows)
{
// Determine the bound data object for the current row
var currentRowObj = row.DataBoundItem;
// Access the data in a particular cell on this row
var cellToTotal = row.Cells["Column1"];
etc
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.