Move node in code behind

2 posts, 0 answers
  1. Jiri
    Jiri avatar
    23 posts
    Member since:
    Aug 2013

    Posted 03 Aug 2015 Link to this post

    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.

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 04 Aug 2015 Link to this post

    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
  3. DevCraft banner
Back to Top