数据绑定 – ListBox不显示对DataSource的更改
发布时间:2020-12-15 08:43:55 所属栏目:百科 来源:网络整理
导读:我认为这是一个简单的问题,但我在网上找不到任何信息.我正在使用BindingSource将ListBox绑定到List,如下所示: ListCustomer customers = MyMethodReturningList();BindingSource customersBindingSource = new BindingSource();customersBindingSource.Data
我认为这是一个简单的问题,但我在网上找不到任何信息.我正在使用BindingSource将ListBox绑定到List,如下所示:
List<Customer> customers = MyMethodReturningList(); BindingSource customersBindingSource = new BindingSource(); customersBindingSource.DataSource = customers; customersListBox.DataSource = customersBindingSource; 现在,当我在客户列表中添加或删除时,我的ListBox会更新(即使不在BindingSource上使用ResetBindings),但如果我更改列表中的任何客户对象,则不会.调用ResetBindings无效.我甚至实现了自己的BindingList,但行为没有改变. 我在.Net 2.0中使用C#. 有任何想法吗? 谢谢 解决方法
如果你使用BindingList,你甚至不需要BindingSource:
BindingList<Customer> customers = new BindingList<Customer>(MyMethodReturningList()); customersListBox.DataSource = customers; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |