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

RadTreeView: draggin node between trees without deleting it from source

1 Answer 60 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Santiago Pesantez
Top achievements
Rank 1
Santiago Pesantez asked on 26 Mar 2012, 08:08 PM
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.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Mar 2012, 07:17 AM
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.
Tags
TreeView
Asked by
Santiago Pesantez
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or