ListBox不显示对DataSource的更改 [英] ListBox doesn't show changes to DataSource

查看:143
本文介绍了ListBox不显示对DataSource的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为这是一个简单的问题,但是在网路上找不到任何信息。我将列表框绑定到列表使用 BindingSource 像这样:

 列表<客户> customers = MyMethodReturningList(); 

BindingSource customersBindingSource = new BindingSource();
customersBindingSource.DataSource = customers;

customersListBox.DataSource = customersBindingSource;

现在,当我从客户添加或删除列表,我的 ListBox 更新(即使没有使用 ResetBindings BindingSource ),但如果我更改列表中的任何客户对象,它不会。调用 ResetBindings 没有任何效果。我甚至实现了我自己的 BindingList ,但行为没有改变。

客户类使用属性来访问和修改数据。它的 ToString()内容显示在列表中。



我在.Net 2.0中使用C# / p>

任何想法?



谢谢

解决方案

如果您使用 BindingList ,您甚至不需要 BindingSource

  BindingList< Customer> customers = new BindingList< Customer>(MyMethodReturningList()); 
customersListBox.DataSource = customers;


I thought this was a simple problem, but I can't find any information on the web. I'm binding a ListBox to a List using BindingSource like so:

List<Customer> customers = MyMethodReturningList();

BindingSource customersBindingSource = new BindingSource();
customersBindingSource.DataSource = customers;

customersListBox.DataSource = customersBindingSource;

Now, when I add or delete from customers list, my ListBox gets updated (even without using ResetBindings on BindingSource), but if I change any of the customer objects in the list, it does not. Calling ResetBindings has no effect. I even implemented my own BindingList, but the behaviour hasn't changed.
The Customer class uses properties for accessing and modification of data. Its ToString() content is displayed in the list.

I'm using C# in .Net 2.0.

Any ideas?

Thanks

解决方案

If you use a BindingList you don't even need the BindingSource:

BindingList<Customer> customers = new BindingList<Customer>(MyMethodReturningList());
customersListBox.DataSource = customers;

这篇关于ListBox不显示对DataSource的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆