通用IBindingListView实现

Bra*_*ach 20 .net data-binding

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

我将目前的选项视为:

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

显然,第一个选择是我的首选.

Aar*_*ner 16

我使用并构建了几年前我在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");
Run Code Online (Sandbox Code Playgroud)

  • +1五年后,这看起来仍然是一个伟大的实施.我没有找到任何更好的支持排序和过滤的开箱即用. (4认同)
  • 有人在使用 BindingListView 时遇到过这个异常吗?它只是说“发现了不明确的匹配。” (3认同)