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

RadTreeView Remove All Nodes

1 Answer 319 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
MarkBr
Top achievements
Rank 2
MarkBr asked on 30 Dec 2008, 04:50 AM
Hi there,

is there a method to delete all nodes from a RadTreeView at one go? I've tried "this.Items.Clear()" but that doesn't seem to delete all nodes. "this.Items.Remove" removes only a given node.

After i've added new nodes i want to be able to see them in the treeview so i'm trying to remove all existing nodes and rebuild the treeview from scratch for the newly added nodes to appear on the treeview..

Is there a better solution to achieve this?

Regards,
Mark.

1 Answer, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 30 Dec 2008, 02:25 PM
Hi Mark,

When I call this method:

treeView.Items.Clear(); 

The all items of the TreeView are removed for me.

Of course these are only the direct items of the TreeView. Since the TreeView is a hierarchical control, it only contains its direct items, which in turn can contain other TreeViewItems and so on. There is no recursive method for removing all items from their parents (I believe this is what you need).

A simple recursive method will do the trick and detach all children from their parents.

If you do not want to deal directly with TreeView nodes, you can use Databinding and modify the respective observable collections. Of course you will not get any help there with recursively detaching children, but it will abstract your logic from the control itself.

Greetings,
Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
MarkBr
Top achievements
Rank 2
Answers by
Miroslav
Telerik team
Share this question
or