This is a migrated thread and some comments may be shown as answers.

Filter items in a RadTreeView

3 Answers 182 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 02 Aug 2012, 03:03 PM
I want to filter the items displayed in a RadTreeView based on the value of a property set on each item.  I'd like to have the tree view reflect the current state of its items whenever this property is changed.  Is this possible?

This is what I've tried so far but I don't know enough about how QueryableCollectionView and FilterDescriptors work to know that I'm using it properly.
public class Node
{
    public string Name { get; set; }
    public bool IsVisible { get; set; }
    public Node(string name, bool isVisible)
    {
        this.Name = name;
        this.IsVisible = isVisible;
    }
}

ObservableCollection<Node> nodes = new ObservableCollection<Node>();
QueryableCollectionView items = new QueryableCollectionView(nodes);
items.FilterDescriptors.Add(
     new FilterDescriptor(
         "IsVisible", FilterOperator.IsEqualTo, true, false, typeof(bool)
      )
);

3 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 07 Aug 2012, 11:04 AM
Hello Jay,

The QueryableCollectionView is just a view over the original collection. This means that if you define a filter in the QueryableCollectionView, it will represent the filtered version of the original collection. So in your case you can set the items collection as the ItemsSource of the RadTreeView. This way it will display the filtered collection. However, as soon as you change the value of the IsVisible property of any item, you'll need to refresh the QueryableCollectionView to reflect the changes and to create a new view of the original collection based on the new settings of the IsVisible property. I attached a sample solution demonstrating this approach.

You can also have a look at this demo solution demonstrating how to filter, sort or search through the RadTreeView ItemsSource collection.

Let me know if that info helps or if I can further assist you.

Greetings,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
naman
Top achievements
Rank 1
answered on 16 Sep 2016, 11:50 AM

Hi,

even I am facing the same problem.

Here IntemSource of radtreeview is a Collection of custom objects, the icon value is taken from the object itself

I am filtering the collection using predicate and getting the filtered values in FilteredCollection.

after reassigning tree is getting filtered but icons are getting disappeared.

ObservableCollection<Object> objectCollection= FilteredCollection;
radTree.ItemsSource = objectCollection;

the same code is getting executed by constructor and that is working fine but after reapplying the filter it is loosing all the icons.

0
Dinko | Tech Support Engineer
Telerik team
answered on 21 Sep 2016, 11:06 AM
Hi ,

Let us start with that this thread is several years old and we prefer to keep separate questions in separate threads because it is easier to follow a conversation - easier for us to answer your questions and easier for you to find our answers. We will ask that you open a new thread for this. Thank you for understanding.

As for your question, we weren't able to reproduce the behavior using only the provided information. Because of this, we would like to ask you for a sample project so that we could examine your scenario directly on our side. Any additional information which you think could help us to better understand your approach will be of great help.

Regards,
Dinko
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
TreeView
Asked by
Jay
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
naman
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or