DragDrop between trees

5 posts, 0 answers
  1. Alex Peachey
    Alex Peachey avatar
    56 posts
    Member since:
    May 2006

    Posted 18 Dec 2007 Link to this post

    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.
  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 19 Dec 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mike
    Mike avatar
    76 posts
    Member since:
    Nov 2004

    Posted 17 Apr 2008 Link to this post

    Do you happen to have an example project of the node 'copy' via drag and drop?

  5. Mike
    Mike avatar
    76 posts
    Member since:
    Nov 2004

    Posted 17 Apr 2008 Link to this post

    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...

    1    private void tvwrVars_DragEnding(object sender, RadTreeViewDragCancelEventArgs e)  
    2         {  
    3             e.Cancel = true;  
    4             RadTreeNode rtnParent = e.TargetNode.GetParentByDepth(0);  
    5             RadTreeView tvwDragTree = (RadTreeView)sender;  
    6             RadTreeNode rtnDragNode = tvwDragTree.SelectedNode;  
    7  
    8             rtnParent.Nodes.Add(rtnDragNode);  
    9         } 

    What am I doing wrong?

    Thanks,
    ~Mike S.
  6. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 21 Apr 2008 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready