views:

126

answers:

2

Hello,

I'm new to Silverlight 4 and the PagedCollectionView. I know it's possible to add a filter to a PCV such as

pvc.Filter = new Predicate(FilterProjectId);

Where pvc is a populated PagedCollectionView.

What I need to do is stack multiple filters to a PCV as I've got a search screen with about 6 fields on it and a DataGrid that's bound to the PCV. Depending on what ComboBoxes are selected, when a search button is pressed, I need to filter the PCV results based on those selections.

I can only seem to get it to take the last filter set. Can anyone provide me with information on how to stack them?

Thanks

A: 

The Filter property is simply a delegate to a function that takes an object and returns a boolean. That function can be as simple or as complex as you choose to write.

Sounds to me that you just need one function contain a series of if blocks that compares the object with each of your 6 fields as necessary then returns the result.

The point is there is no "set of filters" that you can "stack" you just write a filter function that does all you need it to do.

AnthonyWJones
+1  A: 

See my answer to my own question about this: http://stackoverflow.com/questions/3755617/how-do-i-dynamically-construct-a-predicate-method-from-an-expression-tree

I'm using this technique with a PCV. works great.

tobewan
I can see what you're doing when working with a list but the pagedcollectionview takes a predicate<object>, not a predicate<MyClass> so when following your example, I don't see how it relates back to a pcv.
Chris
I added another answer with code for Predicate<object>. Have a look.
tobewan
And if you like the answer, vote on it. thanks.
tobewan