为什么绑定的 DataGridView 单元格没有更新?
我已成功将 DataGridView 绑定到列表。但是,当我以编程方式更改列表中某个对象的某些属性时,网格不会刷新。如果我单击单元格(或最小化然后最大化表单),显示的值将刷新。
我在此处读到我应该使用 BindingList。我使用的列表是一个不实现 IBindingList 的接口类型。但是,用于初始化列表的具体类型确实继承了 BindingList。有什么想法吗?
I have successfully bound my DataGridView to a list. 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. The list I am using is an interface type which doesn't implement IBindingList. But, the concrete type being used to initialize the list does inherit off of BindingList. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的列表必须实现
IBindingList
(或者是BindingList
),并且您的对象必须实现INotifyPropertyChanged
。 DataGridView 正确绑定需要这两个条件。因此,如果您的数据源是
MyList
,则MyList
必须实现IBindingList
和MyClass
必须实现 INotifyPropertyChanged。这是一个简洁的示例: http://crazorsharp.blogspot.com/2009/ 06/inotifypropertychanged-how-to-and-when.html
Your list must implement
IBindingList
(or be aBindingList
) and your object must implementINotifyPropertyChanged
. Both conditions are required for your DataGridView to bind properly.So if your data source would be, for instance,
MyList<MyClass>
,MyList
must implementIBindingList
andMyClass
must implmenentINotifyPropertyChanged
.Here is a neat example: http://crazorsharp.blogspot.com/2009/06/inotifypropertychanged-how-to-and-when.html