TreeView for WinForms | ComponentOne
Node Operations / Drag and Drop Nodes
In This Topic
    Drag and Drop Nodes
    In This Topic

    TreeView supports drag and drop operation within the same treeview as well as among multiple treeviews.

    To perform drag and drop operation on nodes in a treeView, you need to set the EnableDragDrop property of C1TreeView to True. You need to set the AllowDrop property provided by System.Windows.Forms.Control to True for the treeview on which you need to perform the drop operation. Notice that you need to set the EnableDragDrop property to True for each of the multiple treeviews to enable drag and drop for them.

    The C1TreeView class provides the ItemDrag event that occurs when a node is dragged. You can handle this event and use the DraggedData property provided by the C1TreeViewItemDragEventArgs class to get the dragged data. In addition, you can use the Nodes property to get the dragged node.

    See the following code snippet for reference.

    'set the EnableDragDrop property
    C1TreeView1.EnableDragDrop = True
    
    'set the AllowDrop property
    C1TreeView1.AllowDrop = True
    
    // set the EnableDragDrop property
    c1TreeView1.EnableDragDrop = true;
    
    // set the AllowDrop property
    c1TreeView1.AllowDrop = false;
    

    While Dragging

     Dragging nodes

    After Dropping

    Dropped node