Generic IBindingListView Implementations
-
09-06-2019 - |
Question
Can anyone suggest a good implementation of a generic collection class that implements the IBindingListView
& IBindingList
interfaces and provides Filtering and Searching capabilities?
I see my current options as:
- Using a class that someone else has written and tested
- Inheriting from
BindingList<T>
, and implementing theIBindingListView
interfaces - Write a custom collection from scratch, implementing
IBindingListView
andIBindingList
.
Obviously, the first option is my preferred choice.
Solution
I used and built upon an implementation I found on and old MSDN forum post from a few years ago, but recently I searched around again and found a sourceforge project called BindingListView. It looks pretty nice, I just haven't pulled it in to replace my hacked version yet.
nuget package: Equin.ApplicationFramework.BindingListView
Example code:
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");
OTHER TIPS
Here is the help for your method 2 and 3 Behind the Scenes: Implementing Filtering for Windows Forms Data Binding
A couple of solutions I can think of:
The SubSonic Project has a pretty nice implementation of
BindlingList<T>
which is open source. Although this might require using the entire SubSonic binary to use their implementation.I enjoy using the classes from the Power Collections project. It is fairly simple to inherit from one of the base collections there and implement
IBindingListView
.