C# Force ListBox to update elements

岁酱吖の 提交于 2019-12-01 06:07:25

Unfortunately, the data-binding in ListView doesn't support regular (item) change notification events (FooChanged / INotifyPropertyChanged). However, if you know about the change, you can get the list to re-bind itself. Since you are subclassing, you can call:

this.RefreshItems();

or for a single item:

this.RefreshItem(index);

Otherwise, since this isn't public, you can simulate it by changing the DisplayMember:

lb.DisplayMember = "";
lb.DisplayMember = "Bar";

A little hacky, maybe, but it works, and maintains the current selection etc (unlike clearing the DataSource).

Why don't you manually update Text of an item in question? You might also consider rolling out your own databinding mechanism for ListBox. And check out ObjectListView to see if it's of any help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!