Copy node on drag-and-drop

2 posts, 0 answers
  1. paaland
    paaland avatar
    17 posts
    Member since:
    Jun 2009

    Posted 21 Oct 2011 Link to this post

    I have a treeview with drag-and-drop enabled that works fine for moving the nodes around.

    Now I want to add the ability to copy nodes instead of moving them if the CTRL key is held down.

    I can check the CTRL key like this

    ModifierKeys keys = Keyboard.Modifiers;
    bool controlKeyPressed = (keys & ModifierKeys.Control) != 0;

    I use the above logic to differentiate if the backends MoveNode or CopyNode service method is to be called. This works fine and the data is consistent, but the TreeView control seems to automatically remove the source upon a successful drag and drop.

    I can re-insert it if CTRL was down, but I'd rather not have to do that since I might not add to the same position as it was causing the source node to "jump" around.

    Any way to tell the TreeView that this is a copy operation and not a move operation? Also I'd like a way for the visual cue to display a + sign or something similar when CTRL is down.

    A note: This tree is two-way bound to a object so I don't have any specific Drag/Drop event handlers. The treeview modifies the object on drag-and-drop.
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 26 Oct 2011 Link to this post

    Hi Paal Andreassen,

    I prepared a basic project for you that meets your requirements. I use PreviewDragEnded in order to implement the copy logic and DragInfo event of the RadDragAndDropManager in order to set the DragActionContent of the TreeViewDragCue when the Control is pressed. Please examine it and let us know if helps you.

    Greetings,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
Back to Top