How to remove an Item found by .GetItemByPath

4 posts, 1 answers
  1. Peter Meinl
    Peter Meinl avatar
    35 posts
    Member since:
    Jan 2010

    Posted 07 Mar 2010 Link to this post

    I created a TreeView by programmatically adding items.

    I try to remove an item like this:

     

     

    Dim item = treDataSources.GetItemByPath(entiyPath)

     

    treDataSources.Items.Remove(item)

    The item is found.
    But not removed from the tree.
    Items.Count does no decrease after the .Remove.

    What am I doing wrong.

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 11 Mar 2010 Link to this post

    Hello Peter Meinl,

    From the code snippet you provided I couldn't see the type of your ItemsSource collection. If you're using a List collection, the changes you make to the RadTreeView ItemsSource won't affect the original business object, which could cause the problem. If this is the case then you should use ObservableCollection instead of List.

    I have prepared a simple example illustrating how you can populate your RadTreeView with data from code behind. I am using ObservableCollection for the ItemsSource of the RadTreeView. I have added a Delete button that deletes the selected item of the RadTreeView. Please take a look at it and let me know if it helps.

    Please let us know if you need more info.

    Greetings,
    Tina Stancheva
    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Peter Meinl
    Peter Meinl avatar
    35 posts
    Member since:
    Jan 2010

    Posted 09 Apr 2010 Link to this post

    I use treDataSources.Items.Add(...) to populate the tree.
  5. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 12 Apr 2010 Link to this post

    Hello Peter Meinl,

    I modified the example by populating the RadTreeView through the Items property. I also added one more button that deletes one of the items using the RadTreeView  GetItemByPath() method.

    Please note that when you delete an item, it is important to check whether the item has a parent node and if it does, you need to remove the item from its parent's collection, rather than from the RadTreeView Items collection.

    Take a look at the example and let me know if you need more info.

    All the best,
    Tina Stancheva
    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