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

Drag TreeNode from TreeView to windows panel

6 Answers 188 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 06 Dec 2017, 05:45 PM

Hello I am trying to implement the Drag of a tree Node on a Panel (which incidentally is hosted in a usercontrol loaded on the same form as the treeView)

It seems that I manage to enable the drag on the tree node (see the code below) but I don't know how to handle the Drop on the panel; the panel allowdrop property is set to true but the Drop related events (DragOver, DragDrop, DragEnter) are not fired.

What am I doing wrong ? (tvDisplay s my TreeView) 

 

I tried to follow the follwing exemple:

https://stackoverflow.com/questions/27014469/drag-telerik-radtreeview-node-to-textbox-in-c-sharp

 

----------------------------------------------------------------------------

    Private Sub tvDisplay_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles tvDisplay.MouseMove
        If myMouseDown AndAlso IsRealDrag(e.Location, clickedPoint) Then
            Dim node As TreeNodeElement = TryCast((CType(sender, RadTreeView)).ElementTree.GetElementAtPoint(clickedPoint), TreeNodeElement)
            If node IsNot Nothing Then
                CType(sender, RadTreeView).DoDragDrop(node.Data, DragDropEffects.Copy Or DragDropEffects.Move)
            End If
            myMouseDown = False
        End If
    End Sub
    Private Sub tvDisplay_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles tvDisplay.MouseDown
        If e.Button = MouseButtons.Left Then
            myMouseDown = True
            clickedPoint = e.Location
        End If
    End Sub
    Private Shared Function IsRealDrag(ByVal mousePosition As Point, ByVal initialMousePosition As Point) As Boolean
        Return (Math.Abs(mousePosition.X - initialMousePosition.X) >= SystemInformation.DragSize.Width) OrElse (Math.Abs(mousePosition.Y - initialMousePosition.Y) >= SystemInformation.DragSize.Height)
    End Function

 

6 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 11 Dec 2017, 09:28 AM
Hello Pierre,

I have attached a small example that shows how you can achieve this.

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 11 Dec 2017, 02:13 PM

Hello and thanks for your sample program the works, nearly 100% ...

It has a strange behavior that i might have difficulties to explain precisely.

After I clicked on a node and starts a drag (no need to complete the drag) and then I click on another node, I get the "forbidden" icon and the newly clicked node is not selected. But there are cases, that I can not reproduce systematically, where I can select the new node !!!

Furthermore it seems that when I integrate the Drag operation in my "real application", this behavior blocks completely my treeview after I start a drag.

I could record a .avi of this strange behavior if needed.

Regards

PJ Pralong

 

0
Dimitar
Telerik team
answered on 12 Dec 2017, 07:53 AM
Hello Pierre,

The mistake is mine, just add the following code at the beginning of the MouseMove event handler:
If e.Button <> MouseButtons.Left Then
    Return
End If

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 12 Dec 2017, 09:13 AM

Hello

Thank you for your message

However the suggested modification does not change in any manner the problem (actualy I fail to understand how it could make any change since the drag operation in initiated on a left button mousedown).

You can download at the below link a screen capture where you can see that the first drag/drop operation on Node1 works fine, but thereafter it becomes impossible to "click" on another node and make another drag/drop (or any operation at all on the node)

http://winjump.com/docs/ScreenCaptureProject1.zip

Regards

Pierre-Jean

0
Dimitar
Telerik team
answered on 12 Dec 2017, 09:41 AM
Hello Piere,

In the MouseDown event handler, I am only saving the current location. The operation is started in the MouseMove event handler. I have attached a modified version of the project.

I hope this will be useful. 

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 12 Dec 2017, 02:23 PM

Thank your for your message

Please excuse me I misread your previous message

It all works fine.

Best regards

PJ

Tags
Treeview
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Dimitar
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Share this question
or