C#Listbox绑定到实体“实体框架”

时间:2022-12-19 09:51:26

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上的实体表中,但是当表数据发生更改时,我试图调用

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

but nothing happens in ListBox. The Entities.table object holds the right data though, it just doesn't reflect on the ListBox.

但ListBox没有任何反应。 Entities.table对象虽然保存了正确的数据,但它并没有反映在ListBox上。

Any idea??

1 个解决方案

#1


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. 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.

ListBox和其他数据绑定类中有一个优化,如果分配给DataSource的引用没有改变,它基本上不会进行更新。它实际上并不检查数据的内容。事先将其设置为null将保证引用不同。

#1


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. 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.

ListBox和其他数据绑定类中有一个优化,如果分配给DataSource的引用没有改变,它基本上不会进行更新。它实际上并不检查数据的内容。事先将其设置为null将保证引用不同。