简体   繁体   English

C# 列表框绑定到实体“实体框架”

[英]C# Listbox Bound to Entity "Entity Framework"

On my WinForm, I bound my listbox to a Table in Entity on EDMX, but when the table data is changed, I tried to call在我的 WinForm 上,我将我的列表框绑定到 EDMX 上Entity一个表,但是当表数据更改时,我尝试调用

myListBox.DataSource = Entities.table;
myListBox.ResetBindings();
myListBox.Refresh();

but nothing happens in ListBox .但在ListBox什么也没有发生。 The Entities.table object holds the right data though, it just doesn't reflect on the ListBox . Entities.table对象虽然保存了正确的数据,但它只是不反映在ListBox

Any idea??任何的想法??

Try the following尝试以下

myListBox.DataSource = null;
myListBox.DataSource = Entities.table

There is an optimization in the ListBox, and other data binding classes, that basically will not do an update if the reference assigned to DataSource does not change. ListBox 和其他数据绑定类中有一个优化,如果分配给 DataSource 的引用没有改变,基本上不会做更新。 It does not actually do inspection on the contents of the data.它实际上并不检查数据的内容。 Setting it to null before hand will guarantee that the reference is different.事先将其设置为 null 将保证引用不同。

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

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