C# ListBox ObservableCollectionlt;Tgt;(C# ListBox ObservableCollectionlt;Tgt;)
问题描述
我正在尝试使用 ListBox.DataSource = ObservableCollection,但是我不知道如何在我的 OC 更新时让列表框自动更新.我可以在 OC 上挂钩 CollectionChanged 事件,但是我需要对列表框做什么才能使其更新?
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?
推荐答案
根据您的问题,听起来您正在尝试在 WinForms 应用程序中使用 ObservableCollection
.
Based on your question, it sounds like you're trying to use ObservableCollection<T>
in a WinForms application.
ObservableCollection<T>
主要用于 WPF 开发.在 WinForms 中,控件会随着集合的变化而自动更新,您的集合需要实现 IBindingList
.
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
.
最简单的解决方案是使用 BindingList<T>
而不是 ObservableCollection<T>
.之后,您的控件应该随着集合的变化而更新.
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) 类
这篇关于C# ListBox ObservableCollection<T>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# ListBox ObservableCollection<T>


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01