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

DragDrop from any control to treeview

1 Answer 80 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcin Danek
Top achievements
Rank 1
Marcin Danek asked on 16 Sep 2009, 09:27 AM
Hi,
is there any possibility at that moment to handle dropQuery in a treeView? It would be very useful, to be able to set the possibility of dropping specified object on specified tree.
For now, the only possibility I see is to handle PreviewDragEnded event and check for the correct data and handling this event preventing from adding this item. It would be much more useful and readable, if there is a icon telling the user, that he cannot drop specified item on this tree.
The problem is only when dragging items between to tree views. When dragging from another control it is possible to check the DragQuery with status equal to  DropSourceQuery and then it is possible to check the destination control against the allowed destinations for specified object type.
But I don't see any possibility to get it working with two (or more) tree views.

I'm using the latest version of silverlight controls.

Thanks in advance for any help.
Marcin Danek

1 Answer, 1 is accepted

Sort by
0
Accepted
Miroslav
Telerik team
answered on 16 Sep 2009, 11:26 AM
Hello Marcin Danek,

You can handle the DropQuery event of the TreeView and do the check there.

Since the TreeView will normally handle the DropQuery event, you have to sign up using the method overload that lets you handle handled events, like so:

orderView.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(TreeDropQuery), true); 

This is used in the TreeToGrid drag drop example in the online examples.

There you have the TreeViewItem as e.Options.Destination and the payload as well. Setting the e.Query Result to false will make sure that the TreeViewDragCue will visually reflect the impossible drop.

You probably have realized this already, but your payload needs to be enumerable otherwise the TreeView will not accept it (e.g. if the payload is a single item, it will not work, you need to put it in a List).

On a side note, you can handle the DragQuery event by registering for the handled events as well but only one of the events will do.

Hopefully this will help you achieve what you need,

Kind regards,
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
DragAndDrop
Asked by
Marcin Danek
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or