加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

数据绑定 – 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,但行为没有改变.
Customer类使用属性来访问和修改数据.其ToString()内容显示在列表中.

我在.Net 2.0中使用C#.

有任何想法吗?

谢谢

解决方法

如果你使用BindingList,你甚至不需要BindingSource:
BindingList<Customer> customers = new BindingList<Customer>(MyMethodReturningList());
customersListBox.DataSource = customers;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读