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

Drag 'n drop databound

1 Answer 104 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Lucien
Top achievements
Rank 1
Lucien asked on 08 Nov 2011, 09:33 PM
Hi all,

Due to the current lack of support of the RadtreeView for automatic drag and drop when the control is databound, to I am trying to "roll my own". However, I got stuck on a few things, so I really hope someone can help me out.

I have subclassed the RadTreeView, RadTreeViewElement and TreeViewDragDropService classes and am implementing my own versions of OnDragEnter and OnDragDrop. I am assuming that the DragDrop event is the one that I need to override in order to find out on which node the dragged one is dropped.

I can easily find out what node is being dragged by using the value returned in the Data object as below:

drgevent.Data.GetData(typeof(RadTreeNode))

That works fine. However, I am failing to (1) find out what node it is dropped on and (2) what the databound item is for that node. When I use:

var targetNode = this.GetNodeAt(drgevent.X, drgevent.Y)


it always returns null, and I don't see any method or property that returns the item a node is bound to. I was hoping for something similar to the one in the DataGridView (row.DataBoundItem). Is there anything like that, and what do i do to get the node that the dragged item is dropped on?

Thanks in advance (I have been tearing my hair out about this for far too long).

Lucien.

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 11 Nov 2011, 09:16 AM
Hello Lucien,

You should convert the X and Y screen coordinates in client coordinates. You can use the following code snippet: 

C# Version:

RadTreeView treeView;
Point point = new Point(e.X, e.Y);
point = treeView.PointToClient(point);
RadTreeNode node = treeView.GetNodeAt(point);

VB.NET Version:
Dim point As New Point(e.X, e.Y)
point = treeView.PointToClient(point)
Dim node As RadTreeNode = treeView.GetNodeAt(point)

Best wishes,
Svett
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
Treeview
Asked by
Lucien
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or