当前位置: 移动技术网 > IT编程>开发语言>.net > DevExpress 使用 GridControl 时,数据源无法立即更新的问题

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

2019年05月21日  | 移动技术网IT编程  | 我要评论

正太养成指南,568网址导航,日冠王

背景

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网