25

任何人都可以建议一个实现IBindingListView&IBindingList接口并提供过滤和搜索功能的通用集合类的良好实现吗?

我认为我目前的选择是:

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

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

4

3 回答 3

24

我使用并基于几年前在旧 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");
于 2008-10-03T01:23:31.500 回答
4

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

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

于 2010-05-19T20:18:41.100 回答
1

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

  1. SubSonic 项目有一个非常好的实现,BindlingList<T>它是开源的。尽管这可能需要使用整个 SubSonic 二进制文件才能使用它们的实现。

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

于 2008-08-26T22:59:22.610 回答