gpt4 book ai didi

data-binding - ListBox 不显示对 DataSource 的更改

转载 作者:行者123 更新时间:2023-12-04 04:55:40 26 4
gpt4 key购买 nike

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

List<Customer> customers = MyMethodReturningList();

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

customersListBox.DataSource = customersBindingSource;

现在,当我在 customers 中添加或删除时列表,我的 ListBox得到更新(即使不使用 ResetBindings 上的 BindingSource ),但如果我更改列表中的任何客户对象,它不会。调用 ResetBindings没有效果。我什至实现了自己的 BindingList ,但行为没有改变。 Customer类使用属性来访问和修改数据。其 ToString()内容显示在列表中。

我在 .Net 2.0 中使用 C#。

有任何想法吗?

谢谢

最佳答案

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

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

关于data-binding - ListBox 不显示对 DataSource 的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1609544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com