DevExpress 使用 GridControl 時,數據源無法立即更新的問題


背景

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM