BindingSource.ResetBindings不工作,除非";真“;通过

本文关键字:quot 通过 除非 ResetBindings 工作 BindingSource | 更新日期: 2023-09-27 18:26:07

我有一个绑定到BindingSource的网格(它又绑定到List<T>)。当我更改底层List<T>数据,然后调用:时

bs.ResetBindings(false);

网格不会得到更新。但如果我打电话:

bs.ResetBindings(true);

确实得到更新。我的代码现在可以工作了,但我仍然很困惑为什么这是必要的。根据MSDN,ResetBindings的参数应设置为:

true如果数据模式已更改false如果只有值更改了

我当然没有更改任何数据模式。。。那么,为什么我需要true

BindingSource.ResetBindings不工作,除非";真“;通过

如果您有两种类型:Cat和Dog,它们都源自Animal。这将无法正常工作:

来自Designer.cs

animalBindingSource1.DataSource = typeof(Animal);

然后在例如Form_Load 中

List<Cat> cats = getCats();
animalBindingSource1.DataSource = cats;

尝试使用BindingList,例如

animalBindingSource1.DataSource = new BindingList<Animal>(cats);

如果代码不起作用,请发布代码。devexpress网格控件可能没有什么问题。

就这样做吧:

bs.DataSource = ListOfMyObjectOrWhatEver; //EVEN IF ALREADY MADE!
bs.ResetBindings(false);
grid.Refresh();

希望它能帮助。。。