TreeView for WinForms | ComponentOne
Node Operations / Reorder Nodes
In This Topic
    Reorder Nodes
    In This Topic

    In TreeView, you can programmatically reorder nodes using the Move method of the C1TreeNodeCollection class. The Move method can be used with the Nodes collection of either C1TreeView or C1TreeNode. It allows you to move a node from its old position to a new position. The method accepts two parameters, oldIndex and newIndex of the Integer type. Here oldIndex and newIndex specify the old and the new position of the node respectively. The Move method, however, cannot be used to move a child node from one parent node to another.

    The following code snippets moves Child1 from index 0 to index 2 in Parent1.

    ' move a node from its old position to a new position
    parentNode1.Nodes.Move(0, 2)
    
    // move a node from its old position to a new position
    parentNode1.Nodes.Move(0, 2);
    

    Here is an image showing the same.

    Reordering nodes