Drag node to empty tree

2 posts, 0 answers
  1. Lee Malo
    Lee Malo avatar
    29 posts
    Member since:
    Apr 2008

    Posted 25 Jun 2012 Link to this post

    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?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Jun 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top