Update: 19/06/2007 – I have attached a copy of ListBindingSource.cs which I have modified slightly to match against partial field matches (similar to SQL’s LIKE) rather than matching the whole field.
I maintain a C# application and a recent feature request was to be able to search a list of items on a number of attributes. The original implementation used a List<T> as the datasource for a Binding Source. I hit a wall when trying to use the Filter property on the binding source.
It turns out that the Filter property depends on the data source implementing IBindingListView (among others) which apparently List does not. I came accross this article that shows how to implement the IBindingListView.
I’ll admit that I don’t fully understand the whole of the code in the listing but I did manage to figure out where the filtering happens. The class is generic in that you can filter on any public property of the objects used to create your list. It also supports filtering on multiple property through successively setting the Filter property.
To use this class you create a BindingListView<T> and use it as the data source for your binding source.
Note: I was only interested in the Filter ability so I have not looked into the implementation of Sort, or how to modify the SortComparer to sort my objects.