背景 在使用 DevExpress 的 GridControl 為其實現 Checkbox 列,發現如果勾選了三行的數據,在遍歷 GridControl 綁定的數據源時 Checkbox 列的數據僅有 2 行被更新。 原因 使用 Google 搜索了半天,在 DevExpress 的 "Suppor ...
背景
在使用 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.