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

Override drop behavior

1 Answer 269 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 11 May 2015, 08:55 PM

I am using RadTreeView in WPF and need to support drag and drop in the tree view both to move nodes to different 'folders' as well as reorder nodes within a folder. A variety of conditions need to be met for a node to support drag and/or drop so I started by implementing drag and drop directly using the DragDropManager as opposed to the tree view's built in drag/drop behavior. I could not figure out how to reorder nodes using this approach so I reworked it to use the Tree View's drag drop support.

The problem with the later approach is that I don't want the tree view to automatically process the drop. I need to do it to make sure things stay in synch etc. I tried adding my own drop handler and setting e.Handled to true but it was too late. The tree view had already rearranged the data. So, the question is two fold I guess.

1) Is there a way to implement something like the move before/after in the built in drag drop support so I can reorder my tree using the DragDropManager directly?

2) Is there a way to override the drop behavior of the built in drag drop support so I can handle updating the data and hence make sure the rest of the system stays in synch?

Thanks

Dave Goughnour

 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 13 May 2015, 11:08 AM
Hi David,

Let me get straight to your questions:
  1.  Is there a way to implement something like the move before/after in the built in drag drop support so I can reorder my tree using the DragDropManager directly?
    I guess you want to reorder the nodes when you drop inside of a parent item. Is that so? If this is you case you can override the default drop logic and implement custom one inside the drop event handler of DragDropManager. Basically, you can get the TreeViewDragDropOptions and on drop set its DropPosition to None if  you want to restrict the drop. Here is an example:
    DragDropManager.AddDropHandler(this.tree, OnTreeDrop, true);
    //.......................................
    private void OnTreeDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {
        var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
        if (options != null)
        {
            if (my condition is met)
            {
                // cancel the drop of the items
                options.DropAction = DropAction.None;
                 
                //manually insert the items
            }
        }
    }
  2.  Is there a way to override the drop behavior of the built in drag drop support so I can handle updating the data and hence make sure the rest of the system stays in synch?
    I think the above mentioned approach covers this scenario as well. In general, you can subscribe for the DragDropManager events (Drop in your case) and override the default tree view drag/drop behavior by modifying the data in the TreeViewDragDropOptions object.

I you need any further assistance, please, do not hesitate to contact us again.


Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TreeView
Asked by
David
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or