背景
在使用 DevExpress 的 GridControl 为其实现 Checkbox 列,发现如果勾选了三行的数据,在遍历 GridControl 绑定的数据源时 Checkbox 列的数据仅有 2 行被更新。
原因
使用 Google 搜索了半天,在 DevExpress 的 Support 上找到了答案,似乎是需要手动调用 GridControl 关联 View 的 PostEditor() 方法。
解决
在这里我使用的是 GridControl 的 BandedGridView 视图,所以在获取数据源的时候,手动调用一下视图的 PostEditor() 即可。
private void ButtonA_Click(object sender,EventArgs e)
{
bandedGridView1.PostEditor();
if(gricControl1.DataSource is BindingList<ItemDto> items)
{
var checkedItems = item.Where(x=>x.IsUpdate);
}
}
关于 PostEditor() 方法的解释:
posts the value to the associated data source but doesn't close the active in-place editor.
本文探讨了在DevExpress GridControl中实现Checkbox列时遇到的数据更新不全的问题。当多行数据被勾选后,发现只有部分行的数据被正确更新。通过调用PostEditor()方法,可以确保所有被勾选行的数据都能被正确地更新到数据源中。
1094

被折叠的 条评论
为什么被折叠?



