TreeViewItem.Items.RemoveAll() in condition

2 posts, 0 answers
  1. Kelley Wong
    Kelley Wong avatar
    21 posts
    Member since:
    May 2010

    Posted 17 Jun 2011 Link to this post

    The treeview is showed as follows:
    -School           (School Class)
       -Teacher  A          (Teacher Class)
       -Teacher  B
       -Class A         (Class Class)
           -Jim                (Student Class)
       -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 )
  2. Petar Mladenov
    Petar Mladenov avatar
    3162 posts

    Posted 22 Jun 2011 Link to this post

    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.

    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
Back to Top