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

Move node in code behind

1 Answer 47 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jiri
Top achievements
Rank 1
Jiri asked on 03 Aug 2015, 09:13 AM

Hi, I have a TreeView like this.

A

---- A1

---- A2

-------- A21

-------- A22

-------- A23​

---- A3

B

---- B1
---- B2
---- B3​

 

an I need in code behind move node A2 (with all his childrens) to nede B (Parent) at position 1 so new TreeView will look like this: (names will stay, only parent and index will change)

A
---- A1
---- A3
B
---- B1

---- A2
-------- A21
-------- A22
-------- A23​
---- B2
---- B3​

 

Any solution for this?

Thank you.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 04 Aug 2015, 12:23 PM
Hi Jiri,

In order to move a RadTreeViewItem from one parent to another you will need first to remove it from the visual tree. Here is an example how to move an item in a scenario with statically declared RadTreeViewItems.
RadTreeViewItem itemToMove = GetItemToMove();
 
RadTreeViewItem oldParent = itemToMove.ParentItem;
RadTreeViewItem newParent = GetNewParent();
 
oldParent.Items.Remove(itemToMove);
newParent.Items.Add(itemToMove);

Please give this approach a try and let me know if it works for you.

Regards,
Martin
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
TreeView
Asked by
Jiri
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or