Get the treenode under cursor

2 posts, 0 answers
  1. david
    david avatar
    25 posts
    Member since:
    Oct 2008

    Posted 06 Feb 2009 Link to this post

    I need to drag an image into a treeview and when a drop the image a node must be made with
    the imagename.
    I can drag the image an drop it on the treeview but how can I find the node i have selected for the drop??

    the treeview and the image are on a grid and i''m using the draganddropmanager


    is it possible to create a function like GetNodeAt(point mouseposition) ?
  2. Miroslav
    Miroslav avatar
    922 posts

    Posted 10 Feb 2009 Link to this post

    Hi david,

    The drag&drop uses routed events so if you set the IsDropAllowed to each item, so you will be able to handle the DropQuery event for each TreeViewItem by adding a handler at the TreeView. The routed events will travel from each item that your mouse is over, so first an event will travel from the most-nested treeViewitem down the other treeViewItems through the TreeView down to the application root.

    You can handle the event at any point. If the event remains unhandled, the DragDrop will look for another element under the mouse that can accept a drop, e.g. the parent TreeViewItem of the aforementioned item.

    If you would like to "choose" the item as the destination, make sure that the QueryResult of the EventArgs is set to true and that the event is handled (i.e. no other handler will have a say).

    Then, when you handle the DropInfo event there you will have both the e.Options.Source & e.Options.Destination you have agreed to earlier (i.e. there is no need to add variables holding the item for the specific picture).

    treeViewA.AddHandler(RadDragAndDropManager.DragQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnOrganisationTreeDragQuery), false); 

    I have attached an example for dragging items between TreeViews with some logic.


    the Telerik team


    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top