【问题标题】:Generic IBindingListView Implementations通用 IBindingListView 实现
【发布时间】:2010-09-06 22:40:54
【问题描述】:

谁能推荐一个通用集合类的良好实现,它实现了IBindingListViewIBindingList 接口并提供过滤和搜索功能?

我认为我目前的选择是:

  • 使用其他人编写并测试过的课程
  • BindingList<T> 继承,并实现IBindingListView 接口
  • 从头开始编写自定义集合,实现IBindingListViewIBindingList

显然,第一个选项是我的首选。

【问题讨论】:

    标签: .net data-binding


    【解决方案1】:

    我使用并基于几年前在旧 MSDN 论坛帖子中找到的实现,但最近我再次搜索并发现了一个名为 BindingListView 的 sourceforge 项目。它看起来很不错,我只是还没有把它拉进去替换我的黑客版本。

    nuget 包:Equin.ApplicationFramework.BindingListView

    示例代码:

    var lst = new List<DemoClass>
    {
        new DemoClass { Prop1 = "a", Prop2 = "b", Prop3 = "c" },
        new DemoClass { Prop1 = "a", Prop2 = "e", Prop3 = "f" },
        new DemoClass { Prop1 = "b", Prop2 = "h", Prop3 = "i" },
        new DemoClass { Prop1 = "b", Prop2 = "k", Prop3 = "l" }
    };
    dataGridView1.DataSource = new BindingListView<DemoClass>(lst);
    // you can now sort by clicking the column headings 
    //
    // to filter the view...
    var view = (BindingListView<DemoClass>)dataGridView1.DataSource;            
    view.ApplyFilter(dc => dc.Prop1 == "a");
    

    【讨论】:

    • +1 五年后,这看起来仍然是一个很棒的实现。我还没有找到更好的支持开箱即用的排序和过滤功能。
    • 该死的,简单真棒!
    • 不支持 Add 或 LINQ?
    • 有人在使用 BindingListView 时遇到过这个异常吗?它只是说Ambiguous match found.
    • 现在有一个相应的 Nuget 包:equin.applicationframework.bindinglistview
    【解决方案2】:

    这是方法 2 和 3 的帮助 幕后花絮:为 Windows 窗体数据绑定实现过滤

    http://www.microsoft.com/downloads/details.aspx?FamilyID=4af0c96d-61d5-4645-8961-b423318541b4&displaylang=en

    【讨论】:

    • 这里的代码实际上不起作用! originalListItems 值从未设置,因此列表无法正确重置。只要你知道这一点,你就可以在自己的代码中添加。
    • @chris:你是什么意思 originalListItems 值从未设置?它是通过 OriginalList 属性设置的!还是我错过了什么?
    • 这里是该链接的更多上下文:blogs.msdn.com/b/winformsue/archive/2008/05/19/…
    【解决方案3】:

    我能想到的几个解决方案:

    1. SubSonic Project 有一个相当不错的BindlingList&lt;T&gt; 实现,它是开源的。尽管这可能需要使用整个 SubSonic 二进制文件才能使用它们的实现。

    2. 我喜欢使用 Power Collections 项目中的类。从那里的基础集合之一继承并实现IBindingListView 相当简单。

    【讨论】:

    • 是否有更新的 Power Collections 版本?讨论页面讨论了 2011 年 .net 4.0 的更新,但下载页面发布的是 2007 年。
    猜你喜欢
    • 2018-08-23
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多