IBindingListView and Filtering

eric13

Active member
Joined
May 25, 2006
Messages
30
Programming Experience
3-5
Has anybody implemented filtering on a collection of objects through the IBindingListView interface?
 
I have a class called ProjectList that inherits BindingList(Of Project)


I also implements IBindingListView and return True on SupportsFiltering()

When i implement IBindingListView, I'm not sure what to do with the Filter Property

VB.NET:
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property[/COLOR][/SIZE][SIZE=2] Filter() [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Implements [/COLOR][/SIZE][SIZE=2]System.ComponentModel.IBindingListView.Filter[/SIZE]
[SIZE=2][COLOR=#0000ff]   Get[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][COLOR=yellowgreen]       'what goes here?[/COLOR][/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Get[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   Set[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] value [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=yellowgreen]       'w[/COLOR][COLOR=yellowgreen]hat goes here?[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Set[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property[/COLOR][/SIZE]
 
The filter property supports the getting and setting of a string expression that wil be your filter. It's used to 'tailor' the contents of the collection that is presented to anyone using the collection. So you would have a private varaible in your class...

VB.NET:
Private m_StringFilter as string

That is what the getter of the property will return.

Then in the setter you would add this so the filter string can be set..

VB.NET:
Me.m_StringFilter = value

You would probably also have a boolean variable to 'let your class know' that user wants filtering to take place.
 
So, does this apply the filter or do you have to create a custom procedure to apply the filter?
 
I wish!! No, it is exactly what it appears to be just a property block to enable getting and setting of the filter expression. You must as you say create your own method for filtering the collection. It would probably be called directly after the filter has been set, in the set block of the property.
 
Back
Top