New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Drag and Drop Overview

To allow drag and drop functionality in RadTreeView, set the EnableDragAndDrop property to True. Once enabled, dragging behavior by default allows Nodes to be dropped on other Nodes but not between Nodes. Setting EnableDragAndDropBetweenNodes to True allows Nodes to be dropped between other Nodes. A line between the Nodes will display briefly as a visual indicator that the Node can be dropped in the location of the line. To allow multiple Nodes to be dragged at one time, set the MultipleSelect property to True.

You can further tailor the drag and drop behavior per Node by setting the boolean RadTreeNode properties AllowDrag and AllowDrop. Both AllowDrag and AllowDrop properties are True by default.

When RadTreeView detects a valid drag and drop operation (the selected Node is dropped onto another Node or in between Nodes) it generates a NodeDrop server-side event. The event is sent to the source TreeView, i.e. the TreeView from which the Node is being dragged. The event handler for NodeDrop can then perform specific action, by fetching both the source and destination drag/drop Nodes. In the NodeDrop event handler the RadTreeNodeDragDropEventArgs parameter provides access to the following objects:

  • SourceDragNode: The Node being dragged;

  • DestDragNode: The Node being dragged to;

  • DraggedNodes: A collection of Nodes being dragged (this is useful when multi-selection is enabled - MultiSelect property of the RadTreeView is set to True);

  • DropPosition: Indicates the relationship of the Nodes being dropped and can be a RadTreeViewDropPosition enumeration value Above, Below or Over;

  • HtmlElementID: The ID of the HTML element that the Node is being dropped on.

The following example handles the OnNodeDrop event and adds the DraggedNodes to the DestDragNode Nodes collection.

RadTreeView Drad and Drop Overview

ASPNET
<telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView1" runat="server" EnableDragAndDrop="true" EnableDragAndDropBetweenNodes="true"
    MultipleSelect="true" OnNodeDrop="RadTreeView1_NodeDrop" Skin="Vista">
    <Nodes>
        <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1" ExpandMode="ClientSide">
            <Nodes>
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1" ExpandMode="ClientSide">
                    <Nodes>
                        <telerik:RadTreeNode runat="server" ExpandMode="ClientSide" Text="child 1 a">
                        </telerik:RadTreeNode>
                        <telerik:RadTreeNode runat="server" ExpandMode="ClientSide" Text="child 1 b">
                        </telerik:RadTreeNode>
                        <telerik:RadTreeNode runat="server" ExpandMode="ClientSide" Text="child 1 c">
                            <Nodes>
                                <telerik:RadTreeNode runat="server" ExpandMode="ClientSide" Text="child 1 c 1">
                                </telerik:RadTreeNode>
                            </Nodes>
                        </telerik:RadTreeNode>
                    </Nodes>
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
        <telerik:RadTreeNode runat="server" Text="Root RadTreeNode2" ExpandMode="ClientSide">
        </telerik:RadTreeNode>
        <telerik:RadTreeNode runat="server" Text="Root RadTreeNode3" ExpandMode="ClientSide">
        </telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>

To see a live example of the drag and drop support of RadTreeView visit the Drag & Drop live demo.

See Also

In this article
See Also
Not finding the help you need?
Contact Support