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

Drag and Drop in Tree... Difference between inbuilt & RadDragAndDropManager?

1 Answer 77 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ciaran
Top achievements
Rank 1
Ciaran asked on 18 Sep 2009, 01:28 PM
Hi I'm looking at the BugTrackerDragDrop same, inside TeamExplorerView. You don't have the inbuilt one enabled in this demo. So some questions.

1. What's the difference between using the internal IsDragDropEnabled property of the tree together with the IsDropAllowedProperty of the RadTreeViewItem and using attached properties AllowDrag & AllowDrag from the Manager? I notice that by default the internal omethod seems to distinguish inside/after/before but not have arrow cues.  Essentially I'm guessing that if you want to drag external items in you use the manager at the cost of the having the BetweenItemsDragCue/DropPosition. Correct? 

2. These properties are hard coded to true a style for the ItemContainer of a RadTreeViewItem... if I wanted to bind them should I use something like this?

 

 

<telerik:ContainerBindingCollection x:Key="ContainerBindings">

 

 

 

<telerik:ContainerBinding PropertyName="dragDrop:RadDragAndDropManager.AllowDrag" Binding="{Binding CanMove}"/>

 

 

 

<telerik:ContainerBinding PropertyName="dragDrop:RadDragAndDropManager.AllowDrop" Binding="{Binding CanHost}"/>

 

 

 

</telerik:ContainerBindingCollection>

 


3. Could you give an idea of best practice for where to place business rules?
Is it better to Bind to boolean properties (as above) or is Command binding possible or should we handle business logic in the drag/drop events?
I notice that your metadata remarks for the IsDropPossible method of a RadTreeViewItem states that we should use events but which one?
 

 

 

// Remarks:

 

 

 

 

 

// The method makes sure that parents will nto be dropped in their children

 

 

 

 

 

// and that no items will be dropped in a destination which has its IsDropAllowed

 

 

 

 

 

// property set to false.

 

 

 

 

 

// This method is not meant to implement business or application logic. The

 

 

 

 

 

// DragDrop events can be handled to implement additional validation / logic.

 

1 Answer, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 22 Sep 2009, 09:11 AM
Hello Ciaran,

I am sorry for the delayed reply,

When this example was created the TreeView was not yet using the RadDragAndDropManager and in this example it was shown how you can implement dragging to/from the TreeView and other controls.

The current implementation of the TreeView, uses the DragDrop manager and it will handle the DragDrop events itself, so this scenario can be simplified in most cases (I will get back to that later).

To answer your questions:
1. In all versions of the controls after the SP1, the IsDragDropEnabled proeprty of the TreeView specifies whether it will handle the DragDrop events. You can also register for these events, using the overload of the AddHandler method which lets you handle handled events as well:

this.AddHandler(RadDragAndDropManager.DropInfoEvent, new EventHandler<DragDropEventArgs>(OnDropInfo), true); 

With the latest release, you can also make use of the BetweenItemsDragCue, by showing it and hiding it explicitly from the TreeView:

treeView.ShowBetweenItemsDragCue(dropPositionTreeViewItem);  
 
treeView.HideBetweenItemsDragCue(); 

Then the item itself has a property that specifies where is the drop relative to the item:

treeViewItem.DropPosition = DropPosition.Before; 

Then, you can use this helper method on the TreeView item to calclulate where would a drop go:

var dropPosition = treeViewItem.GetDropPositionFromPoint(absoluteMousePosition) 

Currently, you do not lose any functionality if you decide to implement the DragDrop yourself.

The real question is in which case you will write less code - by using only the DragDrop manager and more custom code or relying on the TreeView to handle the events and then setting properties on the TreeView and re-handling some of the events if needed.

My advice here is that if you like the looks and built-in behavior of the TreeView DragDrop, it will be easier to reuse it.

2. If you are not using the build-in TreeView DragDrop this should work, but it will be better if you leave the properties to True and then handle the Drag/DropQuery events appropariately. They are intended to gather information about a possible drag/drop and you will probably need to handle them anyway. I guess that maintaining the state of the properties and handling the events will be harder than just handling the events.

3. Yes, the IsDropPossible method just does a sanity check for the DragDrop.

The business logic of wheter a drag/drop is possible needs to be executed in the Drag/DropQuery handlers. Here are the handlers that will be called during a successful DragDrop operation:

1. DragQuery event with status DragQuery
2. DragInfo event with status DragInProgress

Then when a possible target is reached:
3. DragQuery event with status DropSourceQuery
4. DropQuery event with status DropDestinationQuery
5. DragInfo event with status DropPossible
6. DropInfo event with status DropPossible

On a successful drop:
7. DragInfo event with status DragComplete
8. DropInfo event with status DropComplete

In the query handlers you can get the payload, the source and destination items (controls) as well and do any checks there, then set the e.QueryResult accordingly.

If you have just several DragDrop scenarios, it may be possible to add all the business logic there.
 
If you plan to use DragDrop extensively, it may be useful if your ViewModels implement an interface that will be used to check whether one item can be dragged or dropped into/before/after another item. This way the Drag/Drop query methods could be written in a more generic way.

I have attached a project that shows how you can implement DragDrop between the TreeView and other controls and handle some common scenarios.

Thank you for looking through the DragDrop example. I will be happy to help you with more information / advice if you need,

Sincerely yours,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Ciaran
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or