Drag-and-drop -- how to handle the move/copy myself?

6 posts, 0 answers
  1. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 07 Aug 2013 Link to this post

    Hi telerik,

    After move to the new way of handling drag-and-drop, we've encountered a problem. Basically, we record in our viewmodel object behind the individual treeitem who the parent is. But currently, after the move to new drag-and-drop implementation, it would appear that the dragged item is repositioned 'out-of-the-box' and keeps it's viewmodel -- but in out world, this is now a wrong object.

    Is there a way to prevent the drag-and-drop-manager from doing the actual move? I'd like to do it manually, updating the viewmodel and then notifying the treeview that sending/receiving items have changed...

    Thanks,

    Anders, Denmark
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 09 Aug 2013 Link to this post

    Hello Anders,

    Thank you for contacting us on that matter. As far as I understand your requirement, your business item holds a reference to its parent and you need to update that property when you make drag drop operation. In order to do this you can disable the default drag&drop logic and customize those operations. You can disable the built-in logic by setting the IsDragDropEnabled property of the RadTreeView control to False.

    Furthermore, you can use the events of the DragDropManager to implement your custom logic. For more information you can take a look at this article.

    Don't hesitate to ask if you have any other questions.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 12 Aug 2013 Link to this post

    The article isn't very helpful and does not address my issue.

    I need the treeview to let me know which drag-and-drop the user requests -- and then let me handle the model update and gui update myself.

    Is there a way to signal to the treeview that it should NOT update the GUI?

    Anders, Denmark
  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 14 Aug 2013 Link to this post

    Hello Anders,

    I am not sure that I understand your scenario. Can you please elaborate more on your scenario. Which part of the GUI exactly you don't want to be updated automatically?

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 16 Aug 2013 Link to this post

    Hi Pavel,

    Imagine a treeview where the treeview is mapped to hierachial structures (recursively containing children):
    Root
    -- C1
    -- C2

    When I drag C2 to 'inside C1', I wish to receive notification from the control about this, but I do not want the treeview to do the actual move where C2 appears under C1. I want to update the collections of 'children' of both Root and C1 to update the treeview that way.

    In other words, I want to handle the actual move myself in such a way that if I do not update the model behind the control, nothing is moved!

    Anders
  7. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 21 Aug 2013 Link to this post

    Hello Anders,

    Thank you for the provided clarifications on your scenario.

    You can easily implement your case by allowing the TreeView to execute its built-in drag drop logic and customize the last step of the operation.
    You could attach a handler to the DragDropManger.DropEvent and override the behavior by setting DropAction to None. This will instruct the TreeView to leave source and target items unchanged, i.e. the dragged item will not be moved or copied.
    The actual move/copy logic is located in DragDropManager.DragDropCompleted event, which is fired when the whole drag and drop operation/transaction has been completed. Inside this event handler TreeView checks the DropAction and takes the appropriate steps. This event would be the place where you could insert your custom code modifying source and target collections.

    I am posting a code snippet containing sample code showing my point:

    //// Attach to the appropriate events.
    //// The last parameter "true" is required because RadTreeView handles internally those events.
    DragDropManager.AddDropHandler(treeView, OnDropCompleted, true);
    DragDropManager.AddDragDropCompletedHandler(treeView, OnDragDropCompleted, true);
     
    ...
     
    private static void OnDropCompleted(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {
        var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
        if (options == null)
        {
            return;
        }
     
        //// Tell RadTreeView to do nothing with the data.
        options.DropAction = DropAction.None;
    }
     
    private static void OnDragDropCompleted(object sender, DragDropCompletedEventArgs e)
    {
        var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
        if (options == null)
        {
            return;
        }
     
        //// Deal with the data.
        //// Use the options object to retrieve required information.
    }

    Hope this helps. Please let us know if you need more info.

    Regards,
    Hristo
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready