背景

在使用 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.

相关文章:

  • 2021-11-05
  • 2022-01-14
  • 2022-12-23
  • 2021-08-04
  • 2021-06-01
猜你喜欢
  • 2022-12-23
  • 2021-08-13
  • 2021-11-09
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案