DragDrop from any control to treeview

2 posts, 1 answers
  1. Marcin Danek
    Marcin Danek avatar
    4 posts
    Member since:
    Sep 2009

    Posted 16 Sep 2009 Link to this post

    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
  2. Answer
    Miroslav avatar
    922 posts

    Posted 16 Sep 2009 Link to this post

    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,
    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.
Back to Top