开发者

C# ListBox ObservableCollection<T>

开发者 https://www.devze.com 2022-12-16 18:52 出处:网络
I\'m trying to use a ListBox.DataSource = ObservableCollection, however I can\'t figure out 开发者_运维知识库how to have the listbox automatically update when my OC updates. I can hook the CollectionC

I'm trying to use a ListBox.DataSource = ObservableCollection, however I can't figure out 开发者_运维知识库how to have the listbox automatically update when my OC updates. I can hook the CollectionChanged event on the OC, however what do I need to do to the listbox to make it update?


Based on your question, it sounds like you're trying to use ObservableCollection<T> in a WinForms application.

ObservableCollection<T> is primarily used in WPF development. In WinForms, for the control be automatically updates as the collection changes your collection needs to implement IBindingList.

The easiest solution is to use BindingList<T> instead of ObservableCollection<T>. After that, your controls should update as the collection changes.

MSDN: BindingList(T) Class

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号