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

    The C1TreeNodeCollection class provides the Remove method and the RemoveAt method for removing nodes from TreeView. You can use either of the two methods with the Nodes collection of C1TreeView to remove parent nodes from TreeView. To remove a child node from a parent node or children nodes from a child node, you can use either of the two methods with the Nodes collection of C1TreeNode.

    The Remove method and the RemoveAt method removes a single node at a time. However, to remove all nodes simultaneously from the Nodes collection of TreeView, a parent node, or a child node, you can use the Clear method with the Nodes collection of C1TreeView or C1TreeNode, respectively.

    Here is the code snippet demonstrating how to set these methods.

    ' remove the second parent node from the TreeView Nodes collection
    C1TreeView1.Nodes.Remove(parentNode2)
    
    ' remove the node at index 1
    C1TreeView1.Nodes.RemoveAt(1)
    
    // remove the second parent node from the TreeView Nodes collection
    c1TreeView1.Nodes.Remove(parentNode2);
    
    // remove the node at index 1
    c1TreeView1.Nodes.RemoveAt(1);
    

     After removing the nodes, the treeview appears like the following.

    TreeView after removing nodes