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

How to remove an Item found by .GetItemByPath

3 Answers 43 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Peter Meinl
Top achievements
Rank 1
Peter Meinl asked on 07 Mar 2010, 11:06 AM
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.

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 11 Mar 2010, 02:38 PM
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.
0
Peter Meinl
Top achievements
Rank 1
answered on 09 Apr 2010, 08:02 AM
I use treDataSources.Items.Add(...) to populate the tree.
0
Accepted
Tina Stancheva
Telerik team
answered on 12 Apr 2010, 04:18 PM
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.
Tags
TreeView
Asked by
Peter Meinl
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Peter Meinl
Top achievements
Rank 1
Share this question
or