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

Treeview and DragDropManager

4 Answers 202 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Tuo
Top achievements
Rank 1
Tuo asked on 31 Jan 2013, 05:04 PM
Hello Telerik,
     Some questions about migrating from RadDragDropManager to DragDropManager need your help.
     In our application, DragDrop is only used within one TreeView. So "IsDragDropEnable=True" is set.
     Also, the following event handlers are subscribed to handle dragdrop events:
        1. DragDropManager.AddDragInitializeHandler 
        2. DragDropManager.AddDragDropCompletedHandler
        3. DragDropManager.AddDropHandler'
   The problem is that if drag and drop items in the Treeview only fires DragDropCompleted event .
   The "TargetItem" cannot be acquired through DragDropCompletedEventArgs.
   So DragDropManager is not enough to handle the DragDrop within one TreeView.
   But the RadDragDropManager can.

   While if there are DragDrops among one TreeView and another TreeView or GridView, all the three events can be fired.
   Also, handling the Events  of TreeView: DragEnded, PreviewDragEnded, PreviewDragStarted can work for us. 
  So, the questions are:
    1. How does DragDropManager work for DragDrop in the TreeView?
    2. What are  the differences between using DragDropManager and handling TreeView DragDrop Events?
    3. Do we need to migrate DropManager to the latest one for our case? (Online documentation told us that the DragDropManager fixed some bugs)

  Thanks.
Best,
Tuo

4 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 05 Feb 2013, 04:12 PM
Hi Tuo,

The RadTreeView is still using the old RadDragAndDropManager. However during the next release cycle we will change the RadTreeView built-in drag/drop logic to take advantage of the new DragDropManager. This is why I'd advice you to start building your scenario using the DragDropManager.

At the moment if you set the RadTreeView IsDragDropEnabled property to True, the control internally handles many drag/drop related events and this is why you won't be able to handle the DragDropManager events unless you use the following syntax:
DragDropManager.AddDragInitializeHandler(xTreeView, OnDragInitialize,true);
DragDropManager.AddGiveFeedbackHandler(xTreeView, OnGiveFeedback,true);
DragDropManager.AddDragDropCompletedHandler(xTreeView, OnDragCompleted,true);
DragDropManager.AddDropHandler(xTreeView, OnDrop, true);

However, if you decide to use the DragDropManager to implement your RadTreeView drag/drop logic, I'd recommend setting the IsDragDropEnabled property of the control to False and implementing all drag/drop related logic using the DragDropManager. You may even use behaviors as demonstrated in this demo solution.

I also attached a sample project where I implemented a basic RadTreeView drag/drop scenario using the DragDropManager events. Let me know if it helps or if we can further assist you.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tuo
Top achievements
Rank 1
answered on 06 Feb 2013, 11:03 PM
Hello Stancheva,
        Thank you so much for the detailed answers. It is really helpful.
         Two more questions need your help:
         1. How to dynamically change the DragVisual?
         2. How to get the height of RadTreeViewItem?
          For the first question, there is a need to show different DragCue based on the PossibleDropItem. Such as some items are not allowed to drop, it would be nice to remind user about this by showing "Drop here is not allowed, because ...". I tried to have a local copy of the DragVisual from DragInitialize and then change the DragVisual.ContentTemplate in DragOverItem(DragDropManager.AddDragOverHandler(e.PreparedItem, AddressOf OnItemDragOver)). But it does not work for me.
          For the second one, the TreeViewItemHeight is with the fixed value in the oneline demo(DragDrop:TreeToGrid). I tried to get height from RadTreeViewItem.Height, but it is not set (-1). Since the height may vary a lot, it would be better to get it in fly. While the height is useful for deciding DropPosition, it is would be good to have a way to get that height.
       
Best,
Tuo
0
Tina Stancheva
Telerik team
answered on 11 Feb 2013, 10:29 AM
Hello Tuo,

In order to dynamically change the DragVisual it would be better to extend the DragVisual.ContentTemplate and add a TextBlock control with further information about the state of the drop (possible/impossible) - you can bind the Visibility or the Text of the TextBlock to a business property that can be dynamically changed. Based on the value of the business property, you can use a converter to dynamically change the Visibility/Text of the TextBlock.

As for the RadTreeViewItem Height property - I am not sure how/where you'd like to access it but you can try getting the RadTreeViewItem.ActualHeight property. However, please make sure that the RadTreeViewItem is initialized so that its Height settings are properly calculated.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tuo
Top achievements
Rank 1
answered on 11 Feb 2013, 04:13 PM
Hello Stancheva,
       Thank you so much for your solution, it works perfectly.
Best,
Tuo
Tags
DragAndDrop
Asked by
Tuo
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Tuo
Top achievements
Rank 1
Share this question
or