Is there a filtering option anywhere in XamDataTree?
Ordinary TreeView has TreeView.Items.Filter, but I couldn't find anything like that here.
Thanks in advance.
At this time the only way to do this is to apply filtering on the collection used for the ItemsSource, for example if you were using a CollectionView you would apply the filtering to that. The XamDataTree will respect the filtering applied to the collection and only show the items that should be shown.
I am going to submit a new feature request for an implementation of filtering through the XamDataTree rather than having to perform it on the collection.
Could you please post a working example of filtering nodes using a CollectionView?
Hello Amilcar,
Please see the following forum post: http://www.infragistics.com/community/forums/p/60098/305178.aspx
Thank you for this example. This definitely helps but the example itself is not working properly. For example, if I type "China" in the filter value, it should show me "Asia" and it's children since "China" is a child node of "Asia". Unfortunately, it just filters everything out.
If you look at the code for filtering with the CollectionView you will see that it only filters the first level. As Jason said before, filtering is done entirely through the CollectionView so the example was just to demonstrate that. You will have to modify the CollectionView filter in order to filter multiple levels.
As an example I have attached an updated version of that sample to filter on additional levels. It is by no means a complete implementation but is meant as guidance/demonstration.
Thank you so much! I'll give this example a try but it looks pretty good as a start.
Hey Guys,
I was able to use your example to filter the tree children perfectly! The following segment
private void xamDataTree1_Loaded(object sender, RoutedEventArgs e)
{
view = CollectionViewSource.GetDefaultView(xamDataTree1.ItemsSource);
xamDataTree1.ItemsSource = view;
}
is a little weird to me though. It looks like you're creating a collection view using the tree's itemSource then you're reassigning the tree's itemSource to the recently created collection view - correct me if I'm wrong but this is essentially saying x=y and then saying y=x. Why is the second line needed? If I remove it, the filter no longer works.
I also tried moving the logic out of the code behind and into a view model. In the process, I did the following:
Although I know this is filtering my tree - I have another control that shares the itemSource and this is properly filtering - the tree itself is not hiding the filtered items. Any thoughts on why?
Scratch my last post. I just understood what the line was for and I was able to get the filtering to work through the view model. Thanks again!