This is a migrated thread and some comments may be shown as answers.

Drag node to empty tree

1 Answer 75 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Lee Malo
Top achievements
Rank 1
Lee Malo asked on 25 Jun 2012, 08:43 PM
I need to be able to drag a node to an empty tree, I notice in the demo if you drag all nodes from a tree you can't drag them back. Any suggestions?

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jun 2012, 01:58 PM
Hi Lee Malo,

Try the following sample code snippet for dragging nodes to an empty tree.Hope this helps
aspx:
<telerik:RadTreeView EnableDragAndDrop="True" ID="RadTreeView1" runat="server" OnClientNodeDropping="nodeDropping"
    OnNodeDrop="RadTreeView1_NodeDrop">
    <Nodes>
        <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1">
            <Nodes>
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
        <telerik:RadTreeNode runat="server" Text="Root RadTreeNode2">
            <Nodes>
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
        <telerik:RadTreeNode runat="server" Text="Root RadTreeNode3">
        </telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>
<telerik:RadTreeView EnableDragAndDrop="true" ID="RadTreeView2" runat="server" Width="200px"
    Height="200px" Style="border: 1px solid red" />
JS:
<script type="text/javascript">
function nodeDropping(sender, args)
 {
   if (args.get_htmlElement().id != "RadTreeView2")
   args.set_cancel(true);
 }
</script>
C#:
protected void RadTreeView1_NodeDrop(object sender, RadTreeNodeDragDropEventArgs e)
{
  if (e.DestDragNode == null)
   {
      RadTreeView2.Nodes.Add(e.DraggedNodes[0]);
   }
}

Thanks,
Princy.
Tags
TreeView
Asked by
Lee Malo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or