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

Drag Anything Onto TreeView With Appropriate Cursor

3 Answers 125 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Pawz
Top achievements
Rank 1
Pawz asked on 06 May 2009, 02:25 AM
Hi,

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?!

3 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 11 May 2009, 09:37 AM
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)  
{  
    if(e.Data.GetDataPresent(typeof(RadListBoxItem)))  
    {  
        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);  
      
    parent.Nodes.Add(newNode);  
}  
 
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.

Greetings,
Victor
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.
0
Raj Sharma
Top achievements
Rank 1
answered on 15 Feb 2010, 06:28 PM

 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.

Thanks
0
Victor
Telerik team
answered on 16 Feb 2010, 09:29 AM
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,
Victor
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.
Tags
Treeview
Asked by
Pawz
Top achievements
Rank 1
Answers by
Victor
Telerik team
Raj Sharma
Top achievements
Rank 1
Share this question
or