简体   繁体   English

为什么绑定的DataGridView单元格没有更新?

[英]Why aren't bound DataGridView cells being updated?

I have successfully bound my DataGridView to a list. 我已成功将DataGridView绑定到列表中。 But, the grid doesn't refresh when I programatically change some of the properties of one of the objects within the list. 但是,当我以编程方式更改列表中某个对象的某些属性时,网格不会刷新。 If I click in the cell (or minimize and then maximize form), the displayed value is refreshed. 如果我单击单元格(或最小化然后最大化表单),则刷新显示的值。

I read here that I should use a BindingList. 在这里读到我应该使用BindingList。 The list I am using is an interface type which doesn't implement IBindingList. 我使用的列表是一个不实现IBindingList的接口类型。 But, the concrete type being used to initialize the list does inherit off of BindingList. 但是,用于初始化列表的具体类型确实继承了BindingList。 Any ideas? 有任何想法吗?

Your list must implement IBindingList (or be a BindingList ) and your object must implement INotifyPropertyChanged . 您的列表必须实现IBindingList (或者是BindingList ),并且您的对象必须实现INotifyPropertyChanged Both conditions are required for your DataGridView to bind properly. DataGridView正确绑定需要这两个条件。

So if your data source would be, for instance, MyList<MyClass> , MyList must implement IBindingList and MyClass must implmenent INotifyPropertyChanged . 所以,如果您的数据源是,例如, MyList<MyClass>MyList必须实现IBindingListMyClass必须implmenent INotifyPropertyChanged

Here is a neat example: http://crazorsharp.blogspot.com/2009/06/inotifypropertychanged-how-to-and-when.html 这是一个很好的例子: http//crazorsharp.blogspot.com/2009/06/inotifypropertychanged-how-to-and-when.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM