简体   繁体   中英

How to force a ListBox to reload data in WinForm

I have a ListBox on a Windows Form that is populated during the Form_Load event like so.

        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";
    }

The GetComputerList returns a ComputerList Object that inherits from BindingList<>

I have a button on the form that when clicked updates the table that is the source of the data for the ComputerList Object.

After it is done updating I just want to force the ListBox to repoulate itself with the fresh data from the DB.

How can I do this?

将您的加载代码抽象到一个单独的函数中,然后从您的Form_Load和按钮单击事件中调用该函数。

this should work..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM