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

DragDrop between trees

4 Answers 199 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Alex Peachey
Top achievements
Rank 1
Alex Peachey asked on 19 Dec 2007, 02:09 AM
I've got two trees in my form. One has a list of items and one has a list of categories those items can go into. The items don't have to be in a category and they can be in more than one category.

I'd like the user to be able to drag a node from the list tree and capture that it is dropped on a category and have it show up as a child node under that category. By default this works but the node is actually removed from the list tree and put in the other tree. I'd like it to not get removed from the list but have it act more like a copy operation than a move.

I'm sure I can make this work by capturing the right events and adding in some logic, but before going through the trouble of tracking down exactly what I needed to do, I wanted to make sure I wasn't missing some kind of flag or setting on the tree that would do exactly what I'm talking about automatically.

4 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 19 Dec 2007, 12:25 PM
Hello Alex Peachey,

Thank you for contacting us.

RadTreeView
for WinForms currently only supports node moving in drag and drop operations.

You should be able to copy the dragged node if you handle the DragEnding event of RadTreeView.
Then, in the Cancel handler method of the drag and drop operation use the Node, TargetNode and Direction properties of the event arguments to implement copy functionality.

If you have additional questions, please contact us again.

All the best,
Jordan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mike
Top achievements
Rank 2
answered on 17 Apr 2008, 03:38 PM
Do you happen to have an example project of the node 'copy' via drag and drop?

0
Mike
Top achievements
Rank 2
answered on 17 Apr 2008, 05:25 PM
Hi Telerik,

Okay guys I need some help ASAP.

I have tried to do as you suggested and the drag event is not getting cancelled.

Here is my code...

   private void tvwrVars_DragEnding(object sender, RadTreeViewDragCancelEventArgs e)  
        {  
            e.Cancel = true;  
            RadTreeNode rtnParent = e.TargetNode.GetParentByDepth(0);  
            RadTreeView tvwDragTree = (RadTreeView)sender;  
            RadTreeNode rtnDragNode = tvwDragTree.SelectedNode;  
 
            rtnParent.Nodes.Add(rtnDragNode);  
        } 

What am I doing wrong?

Thanks,
~Mike S.
0
Nikolay
Telerik team
answered on 21 Apr 2008, 07:55 AM
Hi mike scardina,

The drag event is canceled, but right after that, the code snippet for moving the node is executed. So the result behavior is imitating the case where no cancelation of the drag and drop event is made.
 
As to the 'copy via drag and drop' scenario, you should use the Clone() method of the e.Node to get the clone of the dragged node rather than its original. I have demonstrated this in the sample project attached. Please note that, once the event is canceled, you should keep in mind the Direction in which the node is inserted.

Generally, RadTreeView implements the copy scenario without any code from your side. Holding the Alt key when dragging will move a copy of the desired node to the new place.

If you have additional questions, do not hesitate to contact me.

Best wishes,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Treeview
Asked by
Alex Peachey
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Mike
Top achievements
Rank 2
Nikolay
Telerik team
Share this question
or