ListView WinForms Bind to ObservableCollection<T>

本文关键字:lt gt ObservableCollection WinForms Bind to ListView | 更新日期: 2023-09-27 18:29:37

是否可以将ObservableCollection绑定到Winforms中的ListView?我看到的所有例子都是WPF的,但我找不到任何Winforms的例子。

理想情况下,我想绑定以下内容:

ObservableCollection<List> accounts = new ObservableCollection<List>();
accounts.add("someuser");
accounts.add("someotheruser");

到ListView。使用ObservableCollection(可以在WPF中完成),这样对ObservableCollections的任何更改都会导致ListView更新。

这是我尝试过的——在黑暗中刺一刀。。。

groups.Add(new Group
{
    title = "Mathematics Group",
    id = "034234",
    members = "54"
});
listViewGroups.CheckBoxes = true;
listViewGroups.Columns.Add("checkbox", "");
listViewGroups.Columns.Add("groupid", "Group ID");
listViewGroups.Columns.Add("groupname", "Group Name");
listViewGroups.DataBindings.Add("groupname", groups, "title");

有可能吗?

ListView WinForms Bind to ObservableCollection<T>

答案很晚,但供将来参考。

.NET WinForms中的ListView不支持数据绑定。

ObjectListView——一个围绕ListView的开源增强包装——确实如此。

这是可能的,但您可能需要使用一些提供INotifyPropertyChanged接口的外部库。您可以使用PostSharp