ListBox不显示对DataSource的更改

Bła*_*app 6 data-binding listbox c#-2.0

我认为这是一个简单的问题,但我在网上找不到任何信息.我正在将ListBox绑定到像这样的List使用BindingSource:

List<Customer> customers = MyMethodReturningList();

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

customersListBox.DataSource = customersBindingSource;
Run Code Online (Sandbox Code Playgroud)

现在,当我从添加或删除customers列表中,我ListBox被更新(即使没有使用ResetBindingsBindingSource),但如果我更改任何客户对象的列表,它没有.通话ResetBindings无效.我甚至实现了自己的BindingList,但行为没有改变.
Customer类使用属性用于访问和数据的修改.其ToString()内容显示在列表中.

我在.Net 2.0中使用C#.

有任何想法吗?

谢谢

Chu*_*bur 5

如果你使用a BindingList甚至不需要BindingSource:

BindingList<Customer> customers = new BindingList<Customer>(MyMethodReturningList());
customersListBox.DataSource = customers;
Run Code Online (Sandbox Code Playgroud)


小智 4

好的,这是一个肮脏的修复:无论何时您都需要刷新设置 datasource = null 的框内容,然后重新绑定它。

它不更新的原因是列表中的对象没有更改,并且它只检查对象的引用而不是其内容。