We pay for user submitted tutorials and articles that we publish. Anyone can send in a contributionLearn More
A while back I wrote an article about How to sort data by manipulating the view only, This article will handle filtering the data without changing it.
I had a large collection that I needed to display and allow the user to filter it using many parameters. After searching for a while I found a very elegant solution:
what are predicates? I will Quote
Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.
You can read more about it here.
A predicate Is a template so you will have to specify the type for instance:
Where the “SomeFunction” needs to be of type bool func(object) for instance:
We are assuming that the collection holds int types, but incase the object is a complex one you can check everything you want inside this predicate.
Using it is very simple. All you have to do is specify the predicate to the Items control that displays the data:
I found that setting the filter to null before applying if will make sure no residue is left from other filters. To remove the filtering all you have to do is just set it to null:
Now you can filter your collection with out having to handle that data.
Tags :Applym CollectiondelegatefilteringItem ControlPredicate
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd