DevExpress 使用 GridControl 时,数据源没法当即更新的问题

背景

在使用 DevExpress 的 GridControl 为其实现 Checkbox 列,发现若是勾选了三行的数据,在遍历 GridControl 绑定的数据源时 Checkbox 列的数据仅有 2 行被更新。express

缘由

使用 Google 搜索了半天,在 DevExpress 的 Support 上找到了答案,彷佛是须要手动调用 GridControl 关联 View 的 PostEditor() 方法。post

解决

在这里我使用的是 GridControl 的 BandedGridView 视图,因此在获取数据源的时候,手动调用一下视图的 PostEditor() 便可。code

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() 方法的解释:ci

posts the value to the associated data source but doesn't close the active in-place editor.get

相关文章
相关标签/搜索