简体   繁体   English

绑定到ObservableCollection的ListView WinForms <T>

[英]ListView WinForms Bind to ObservableCollection<T>

Is it possible to bind an ObservableCollection to a ListView in Winforms? 是否可以将ObservableCollection绑定到Winforms中的ListView? All the examples I'm seeing are for WPF but I can't find anything for Winforms. 我看到的所有示例都是针对WPF的,但是对于Winforms我找不到任何东西。

Ideally I'd like to bind the following: 理想情况下,我想绑定以下内容:

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

... to the ListView. ...到ListView。 Using an ObservableCollection (as can be done in WPF) so that any changes to the ObservableCollection will cause the ListView to update. 使用ObservableCollection(可以在WPF中完成),以便对ObservableCollection进行任何更改都将导致ListView更新。

Here's what I've tried - taking a stab in the dark ... 这就是我尝试过的-在黑暗中刺伤...

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");

Is it possible? 可能吗?

Very late answer, but for future reference. 答案很晚,但可供将来参考。

ListView in .NET WinForms does not support data binding. .NET WinForms中的ListView 支持数据绑定。

ObjectListView -- an open source enhancement wrapper around a ListView -- does. ObjectListView是一个围绕ListView的开源增强包装。

It's possible but you may need to use some external library that provides INotifyPropertyChanged interface. 有可能,但是您可能需要使用一些提供INotifyPropertyChanged接口的外部库。 You can use PostSharp for that. 您可以为此使用PostSharp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM