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

RadTreeView and DragAndDrop

5 Answers 148 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
christina noel
Top achievements
Rank 1
christina noel asked on 21 Aug 2012, 04:22 PM
I am using RadTreeView and RadGrid to implement a file explorer. The RadTreeView shows just folders in their proper tree to allow swift navigation, and the RadGrid shows folders and files. I am trying to make it possible for a user to drag files from the grid to the folder view in order to move or copy files. We are not allowing folders to move, just files. In case it matters, the RadTreeView uses a Hierarchical Data Template to display its bound ItemsSource (an ObservableCollection) and is using LoadOnDemand to improve performance.

As such, I have managed to use RadDragAndDropManager to allow me to drag just file rows off the RadGrid, but I am having problems getting them to drop properly onto the RadTreeView. I have the following requirements:

1) RadTreeViewItems cannot be dragged (they are folders)
2) RadTreeViewItems are valid drop targets for the Grid rows.
3) The TreeView itself is not a valid drop target (just the items), and insertion is not allowed.
4) I need a specialized DropCue that changes based on whether the user is pressing the Shift key (this switches it between Move and Copy).
5) When the Grid row is dropped, it does not appear in the tree. Instead, the underlying file needs to be moved or copied.

I've tried "IsDragAndDropEnabled" on the RadTreeView: Didn't work because the RadTreeViewItems are draggable, and even when I figured out that I needed to handle DragQuery to stop that, the DropCue wasn't customizable anywhere I tried.
I've tried "RadDragAndDropManager.AllowDrop" on the RadTreeView: Didn't work because the e.Options.Destination is the treeview (this would be acceptable if there's a way to figure out which item we're on when dropping that I haven't found)
I've tried "RadDragAndDropManager.AllowDrop" in the Style of the RadTreeViewItems: Didn't work because I can't figure out how to make every item in the tree handle the DragAndDropManager events.

I'd appreciate any help with implementing this correctly. The last piece of any of these three approaches would be great, or some other path I can use to implement this.

--CHristina

5 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 23 Aug 2012, 05:08 AM
Hi,

I'd like to suggest you the new DragDropManager. It provides some new features and events which you may find useful. Also all new features and bug fixes will be applied on the DragDropManager. You can read more about it in our online help here, I suggest you to take a look at the article "DragDropManager Migration".
Now for your questions:
1) Don't set DragDropManager.AllowDrag for the RadTreeViewItems (or set it to false).
2) Set AllowDrop for all RadTreeViewItems.
3) Set the AllowDrop for the TreeView to false (or just don't set it at all).
4) You can define your DragVisual in your DragInitialize Event Handler.
5) You can do whatever you want with the dropped item in your Drop Handler, there's no need to show the item after it's dropped, you decide what to do with it.

To figure out which is the dragged item you need to set your args.Data in the DragInitialize Event Handler and after that you may use it in your Drop Handler:
private void OnDragInitialize(object sender, DragInitializeEventArgs args)
{
    args.AllowedEffects = DragDropEffects.All;
    var payload = DragDropPayloadManager.GeneratePayload(null);
    payload.SetData(typeof(ApplicationInfo), ((FrameworkElement)args.OriginalSource).DataContext);
    args.Data = payload;
             
    args.DragVisual = new ContentControl
    {
        Content = args.Data, ContentTemplate = LayoutRoot.Resources["ApplicationTemplate"] as DataTemplate
    };
}

You may check our online demos - we have an example for DragDrop from RadTreeView to RadGrid here.

Feel free to contact us in case of any problems.

Regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
christina noel
Top achievements
Rank 1
answered on 23 Aug 2012, 06:56 PM
I'm currently on version 2011 Q3, so I have the DragDropManager, but it doesn't look like I have PayloadManager capability. I have some screenshots of the way it's been working with RadDragAndDropManager, but I'm still trying to figure out how to attach them.

When you drag the grid rows, you can see the list of items (I have a datatemplate for that) and a Drag Cue. The Drag Cue shows a "No" symbol when you can't drop (over the grid and over portions of the TreeView where dropping is not allowed), or text that we change based on which button you are pushing (currently set in DropQuery):

TreeViewDragCue cue = (e.Options.DragCue as TreeViewDragCue);
ModifierKeys keys = Keyboard.Modifiers;
bool shiftKey = (keys & ModifierKeys.Shift) != 0;
bool controlKey = (keys & ModifierKeys.Control) != 0;
            
cue.DragActionContent = controlKey ? "Copy to Folder" : (shiftKey ? "Move to Folder" : "Add to Folder");

This is working for dragging (and not dropping) in the grid, and is giving correct cues for RadBreadcrumbBarItems when I attach DropQuery/DropItem to the BreadCrumbBar, but it is NOT working for RadTreeViewItems, because the drop is considered to be on the RadTreeView, not on the items.

As I stated before, I've been trying to work around all that. My initial attempt at DragDropManager has run up against a lot of incomplete or unhelpful documentation, and here are my remaining issues:
1) I'm having problems getting my dragged files to appear. I'm setting e.Data to a List, and e.DragVisual to a DragVisual object with the e.Data as Content and a DataTemplate as the ContentTemplate. Is that DataTemplate supposed to include a structure for displaying that List, or should it just be a per-item DataTemplate?
2) I don't understand how to get a DragCue (other than what looks like the standard MS drag cue) to appear so that I can see the big red "No" circle or my special drag cue text.
3) The grid rows aren't showing the standard MS "no drag" cue -- instead they act like you can drop on them. This might be because I am allowing File Drop in that region, but it wasn't happening before.

All in all, I'm not impressed with DragDropManager. I much prefer the RadDragAndDropManager -- it's much prettier. I just want it to work with my RadTreeViewItems!

--Christina
0
Tina Stancheva
Telerik team
answered on 28 Aug 2012, 01:21 PM
Hi Christina,

Thank you for your elaborate response. Actually as the RadTreeView is still using internally the RadDragAndDropManager, it would be a lot easier for you to iplement your requirements using that manager.

Unfortunately as I am not sure how you've implemented your custom logic, it's hard for me to create a sample solution to demonstrate the scenario you described in detail. However, you can examine this demo as it demonstrates something similar to your requirements - basically in the Future Projects RadTreeView you can't drag or reorder the items, you can only drag the staff from the Staff tree into the Future Projects RadTreeViewItems - which means that you can't drop new items in this tree, only populate the ItemsCource collection fo each of its items. Please examine the OnDropQuery method implementation as its logic should help you implement the first three requirements, listed in your initial post.

Now for the DragCue - the approach with changing the TreeViewDragCue.DragActionContent should work in the RadDragAndDropManager.DragInfo event handler - is this where you've implemented it?

Also, if you can start a support tickect and attach your original solution or a sample solution demonstrating your approach and your issues (especially the last one from your initial post), we will gladly look into it and suggest an approach for implementing all requirements. 

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
christina noel
Top achievements
Rank 1
answered on 28 Aug 2012, 03:58 PM
Thanks for your response, Tina!

I have opened a support ticket, but I thought I'd answer your direct questions anyway.

In the demo you pointed me at, the FutureProjects items ARE draggable... they just won't drop anywhere. I don't want my users to even be able to pick up the items in my RadTreeView.

I have been updating the DragActionContent in DropQuery, not DragInfo. I was doing this for stylistic reasons because that cue seemed to be a function of where we were about to drop, not what we were dragging. I just tried DragInfo with no change in behavior (copied the code from DropQuery, so it was in both).

My ticket number is 584771, if you wish to help follow up on that.

--Christina
0
Tina Stancheva
Telerik team
answered on 29 Aug 2012, 01:58 PM
Hello Christina,

I responded to the support ticket you sent, but I will post a reply here as well, in case anyone else is following the conversation:

Basically in order to make sure that the items in the RadTreeView won't be draggable, you can handle the RadTreeView.PreviewDragStarted event:

private void tvFolders_PreviewDragStarted(object sender, RadTreeViewDragEventArgs e)
{
    e.Handled = true;
}

And in order to change the DragCue, I'd suggest an approach where the OnDropQuery event handler is used to define which destinations are a possible drop location and which aren't. In order to make a destination a possible drop location, you need to set the QueryResult to True. Then you can handle the DropInto event to change the DragCue if the status of the operation is DropPossible.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DragAndDrop
Asked by
christina noel
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
christina noel
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or