簡體   English   中英

如何強制ListBox在WinForm中重新加載數據

[英]How to force a ListBox to reload data in WinForm

我在像這樣的Form_Load事件期間填充的Windows窗體上有一個列表框。

        private void Form1_Load(object sender, EventArgs e)
    {
        SA.Business.ComputerList computerList;
        computerList = SA.Business.Business.GetComputerList();

        this.lbComputers.DataSource = computerList;
        this.lbComputers.DisplayMember = "Name";
    }

GetComputerList返回一個從BindingList <>繼承的ComputerList對象。

我在窗體上有一個按鈕,單擊該按鈕時將更新作為ComputerList對象的數據源的表。

更新完成后,我只想強制ListBox使用數據庫中的新數據重新填充自身。

我怎樣才能做到這一點?

將您的加載代碼抽象到一個單獨的函數中,然后從您的Form_Load和按鈕單擊事件中調用該函數。

這應該工作..

// after the code to update the source
Form1_Load(null, null);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM