RadTreeView: draggin node between trees without deleting it from source

2 posts, 0 answers
  1. Santiago Pesantez
    Santiago Pesantez avatar
    1 posts
    Member since:
    Mar 2010

    Posted 26 Mar 2012 Link to this post

    I have 2 radtreeview controls in a site, and want to copy one node the other tree control by drag/drop functionality but the source node is being deleted from the source node (cut/paste), I want to emulate the copy functionality, without deleting the node form the source.
    Thanks in advance for the help.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Mar 2012 Link to this post

    Hello,

    Try the following JavaScript to copy nodes between RadTreeViews.

    JS:
    <script type="text/javascript">
     function OnClientNodeDropping(sender, args)
      {
       var sourceNode = args.get_sourceNode();
       var destNode = args.get_destNode();  
       if(destNode)
        {
         sender.trackChanges();
         var newNode = new Telerik.Web.UI.RadTreeNode();
         newNode.set_text(sourceNode.get_text());
         newNode.set_value(sourceNode.get_value());
         destNode.get_nodes().add(newNode);
         CloneNode(newNode, sourceNode);
         destNode.set_expanded(true);
         sender.commitChanges();
        }     
      }
     function CloneNode(newNode, sourceNode)
      {
       if (sourceNode.get_nodes().get_count()>0)
        {
         for (var i = 0; i < sourceNode.get_nodes().get_count(); i++)
          {
           var node = sourceNode.get_nodes().getNode(i);
           var newChildNode = new Telerik.Web.UI.RadTreeNode();
           newChildNode.set_text(node.get_text());
           newChildNode.set_value(node.get_value());
           newNode.get_nodes().add(newChildNode);
           CloneNode(newChildNode, node);
          }
        }
      }
    </script>

    Note: Set EnableDragAndDrop property of RadTreeView to true.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top