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

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

5 Answers 354 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 07 Aug 2013, 05:23 AM
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

5 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 09 Aug 2013, 03:04 PM
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 >>
0
Anders
Top achievements
Rank 1
answered on 12 Aug 2013, 09:47 AM
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
0
Pavel R. Pavlov
Telerik team
answered on 14 Aug 2013, 01:56 PM
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 >>
0
Anders
Top achievements
Rank 1
answered on 16 Aug 2013, 07:42 AM
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
0
Hristo
Telerik team
answered on 21 Aug 2013, 07:56 AM
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 >>
Tags
TreeView
Asked by
Anders
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Anders
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or