C# 重新加载列表框内容

C# 重新加载列表框内容,c#,listbox,reload,C#,Listbox,Reload,当我看到这个帖子 但是在我的代码中,我没有看到任何DataBind()方法 lstBox.DataBind(); 如何在C#Net中重新加载列表框 Refresh()方法也不起作用。您可以尝试将其用作ItemSource,所有操作都会自动完成。然后,您的任务是将项目填充到ObservableCollection中,无需手动更新。您可以尝试将其用作项目源,所有操作都是自动完成的。然后,您的任务是将项目填充到ObservaleCollection中,无需手动更新。DataBind()用于ASP.N

当我看到这个帖子

但是在我的代码中,我没有看到任何
DataBind()
方法

lstBox.DataBind();
如何在C#Net中重新加载
列表框

Refresh()
方法也不起作用。

您可以尝试将其用作ItemSource,所有操作都会自动完成。然后,您的任务是将项目填充到ObservableCollection中,无需手动更新。

您可以尝试将其用作项目源,所有操作都是自动完成的。然后,您的任务是将项目填充到ObservaleCollection中,无需手动更新。

DataBind()用于ASP.NET控件-据我所知,Windows窗体控件没有等效的方法。您的列表框的数据源是什么?我记得不久前遇到过类似的问题,我通过将控件绑定到BindingSource对象(而不是我正在使用的任何对象)来解决我的问题。类似地,将Listbox绑定到BindingSource而不是当前数据源可能会对您有所帮助。发件人:

BindingSource组件有很多用途。首先,它通过在Windows窗体控件和数据源之间提供货币管理、更改通知和其他服务,简化了窗体控件与数据的绑定

换句话说,一旦您对BindingSource进行更改(例如调用BindingSource.Add,或将BindingSource的DataSource属性设置为另一个集合),您的列表框将自动更新,而无需调用类似“DataBind()”的方法

如果listbox当前绑定到集合对象,则只需将集合绑定到BindingSource,然后将控件绑定到BindingSource:

BindingSource.DataSource = ListboxItems;
ListBox.DataSource = BindingSource;
MyBindingSource.Clear();
MyBindingSource.Add(new BusinessObject("Bill", "Clinton", 1946));
MyBindingSource.Add(new BusinessObject("George", "Bush", 1946));
MyBindingSource.Add(new BusinessObject("Barack", "Obama", 1961));

lstBox.DataSource = MyBindingSource;
或者,您可以手动生成BindingSource的内容:

BindingSource.DataSource = ListboxItems;
ListBox.DataSource = BindingSource;
MyBindingSource.Clear();
MyBindingSource.Add(new BusinessObject("Bill", "Clinton", 1946));
MyBindingSource.Add(new BusinessObject("George", "Bush", 1946));
MyBindingSource.Add(new BusinessObject("Barack", "Obama", 1961));

lstBox.DataSource = MyBindingSource;
DataBind()用于ASP.NET控件-据我所知,Windows窗体控件没有等效的方法。您的列表框的数据源是什么?我记得不久前遇到过类似的问题,我通过将控件绑定到BindingSource对象(而不是我正在使用的任何对象)来解决我的问题。类似地,将Listbox绑定到BindingSource而不是当前数据源可能会对您有所帮助。发件人:

BindingSource组件有很多用途。首先,它通过在Windows窗体控件和数据源之间提供货币管理、更改通知和其他服务,简化了窗体控件与数据的绑定

换句话说,一旦您对BindingSource进行更改(例如调用BindingSource.Add,或将BindingSource的DataSource属性设置为另一个集合),您的列表框将自动更新,而无需调用类似“DataBind()”的方法

如果listbox当前绑定到集合对象,则只需将集合绑定到BindingSource,然后将控件绑定到BindingSource:

BindingSource.DataSource = ListboxItems;
ListBox.DataSource = BindingSource;
MyBindingSource.Clear();
MyBindingSource.Add(new BusinessObject("Bill", "Clinton", 1946));
MyBindingSource.Add(new BusinessObject("George", "Bush", 1946));
MyBindingSource.Add(new BusinessObject("Barack", "Obama", 1961));

lstBox.DataSource = MyBindingSource;
或者,您可以手动生成BindingSource的内容:

BindingSource.DataSource = ListboxItems;
ListBox.DataSource = BindingSource;
MyBindingSource.Clear();
MyBindingSource.Add(new BusinessObject("Bill", "Clinton", 1946));
MyBindingSource.Add(new BusinessObject("George", "Bush", 1946));
MyBindingSource.Add(new BusinessObject("Barack", "Obama", 1961));

lstBox.DataSource = MyBindingSource;

“重新加载”是指更新列表框的数据绑定吗?是的,当用户在文本框中输入文本时,我从数据库检索数据并希望重新加载。所谓“重新加载”,是指更新列表框的数据绑定吗?是的,当用户在文本框中输入文本时,我从数据库检索数据并希望重新加载。