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

TreeViewItem.Items.RemoveAll() in condition

1 Answer 37 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kelley Wong
Top achievements
Rank 1
Kelley Wong asked on 17 Jun 2011, 12:08 PM
The treeview is showed as follows:
-School           (School Class)
   -Teacher  A          (Teacher Class)
   -Teacher  B
   -Class A         (Class Class)
       -Jim                (Student Class)
       -Tom
       -Tim
   -Class B
   -Class C

i right click on the Root Note(School) ,it shows a contextmenu to refresh the Teachers
so I want to  use TreeViewItem.Items.RemoveAll(Predicate ) to remove the Teachers on the treeview first
but how to use ItemCollection.RemoveAll(Predicate )

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 22 Jun 2011, 12:54 PM
Hello Kelley Wong,

You cannot filter with Predicate the way you want in Silverlight. If your tree is databound to ObservableCollection, you can filter the source collection and rebind the tree like so:
ObservableCollection<DataItem> col = new ObservableCollection<DataItem>();
            col = new ObservableCollection<string>()(col.Where(x => x.Names.StartsWith("abc")));
            tree.ItemsSource = col;
If your tree is declarative or created from code behind, you have to iterate over the Items collection and use the Remove method if the RadTreeViewitems meets your condition.

Greetings,
Petar Mladenov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Kelley Wong
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or