Drag Anything Onto TreeView With Appropriate Cursor

4 posts, 0 answers
  1. Pawz
    Pawz avatar
    51 posts
    Member since:
    Aug 2007

    Posted 05 May 2009 Link to this post


    I don't know if this is possible with the current control set, but I would like to be able to handle items being dragged onto my treeview in a much more robust manner than currently. Basically, if I drag something onto a tree, I'd like to be able to see the positioning lines and node highlighting that you get if you're dragging a node from one tree to another. I currently have a radGridView and a Listbox that I want to be able to drag from into the tree view.

    I've read in a few posts that Telerik was working on a framework for dragging between controls? Is this complete or still planned? If it is where might I find information about it?

    If it's yet to be developed, I just need a pointer on how to handle the entry of the mouse into the treeview control in order to get it to think it's getting a node from another tree. If I convert the data in the drag event into a radtreenode perhaps..?

    A second question I'd like to know is how to make my cursor look like the treeview's node-dragging cursor?!
  2. Victor
    Victor avatar
    1358 posts

    Posted 11 May 2009 Link to this post

    Hi Andrew,

    Thank you for writing. The Drag And Drop framework is still planned. We are currently working on other features which we have identified as more important. A general Drag And Drop framework is a major feature and we are not there yet. You will have to make use of the standard drag and drop functionality.

    You will have to do the following things:

    1. Handle the mouse down or another appropriate event of the control you want to drag from and call the DoDragDrop() method with your data.

    2. Handle the DragEnter event of RadTreeView and determine whether the incoming data is the data you want (this determines your cursor).

    3. Handle the DragDrop event of RadTreeView. This is where you will do the conversion from a listbox item (for example) to a RadTreeNode.

    Again this is the standard functionality provided by .NET and is pretty straightforward. Here is an example with our controls:

    private void radTreeView2_DragEnter(object sender, DragEventArgs e)  
            e.Effect = DragDropEffects.Copy;  
    private void radTreeView2_DragDrop(object sender, DragEventArgs e)  
        RadListBoxItem item = e.Data.GetData(typeof(RadListBoxItem)) as RadListBoxItem;  
        RadTreeNode newNode = new RadTreeNode(item.Text);  
        Point p = this.radTreeView2.PointToClient(new Point(e.X, e.Y));  
        RadTreeNode parent = this.radTreeView2.GetNodeAt(p.X, p.Y);  
    private void radListBox1_MouseDown(object sender, MouseEventArgs e)  
        if (this.radListBox1.SelectedItem != null)  
            this.radListBox1.DoDragDrop(this.radListBox1.SelectedItem, DragDropEffects.Copy);  

    I am afraid that the line indicators are custom functionality that you will also have to write on your own. Please write back if you need further assistance.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Raj Sharma
    Raj Sharma avatar
    7 posts
    Member since:
    Jan 2010

    Posted 15 Feb 2010 Link to this post

     I also want to drop Object into tree view from a Panel.
     I also want the lines to be shown in the tree view.

    Is this yet possible??
    Please reply. 

    It will be highly appreciated.

  4. Victor
    Victor avatar
    1358 posts

    Posted 16 Feb 2010 Link to this post

    Hi Raj Sharma,

    I am afraid that dropping arbitrary objects on RadTreeView is possible only via the OLE drag & drop mechanism, however, you will not be able to use the drop feedback line because the DoDragDrop() method installs a modal message loop which gobbles up WM_MOUSEMOVE messages.

    Kind regards,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top