任何人都可以建议实现通用集合类的良好实现,实现IBindingListView
&IBindingList
接口并提供过滤和搜索功能吗?
我将目前的选项视为:
使用其他人编写和测试过的类
继承BindingList
和实现IBindingListView
接口
从头开始编写自定义集合,实现IBindingListView
和IBindingList
.
显然,第一个选择是我的首选.
我使用并构建了几年前我在MSDN论坛上发现的一个实现,但最近我再次搜索并找到了一个名为BindingListView的sourceforge项目.它看起来很不错,我还没有把它拉进去替换我的黑客版本.
nuget包: Equin.ApplicationFramework.BindingListView
示例代码:
var lst = new List{ 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 (lst); // you can now sort by clicking the column headings // // to filter the view... var view = (BindingListView )dataGridView1.DataSource; view.ApplyFilter(dc => dc.Prop1 == "a");