Drag TreeNode from TreeView to windows panel

7 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    53 posts
    Member since:
    Apr 2011

    Posted 06 Dec 2017 Link to this post

    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

     

  2. Dimitar
    Admin
    Dimitar avatar
    2362 posts

    Posted 11 Dec 2017 Link to this post

    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.
  3. pierre-jean
    pierre-jean avatar
    53 posts
    Member since:
    Apr 2011

    Posted 11 Dec 2017 in reply to Dimitar Link to this post

    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

     

  4. Dimitar
    Admin
    Dimitar avatar
    2362 posts

    Posted 12 Dec 2017 Link to this post

    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.
  5. pierre-jean
    pierre-jean avatar
    53 posts
    Member since:
    Apr 2011

    Posted 12 Dec 2017 in reply to Dimitar Link to this post

    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

  6. Dimitar
    Admin
    Dimitar avatar
    2362 posts

    Posted 12 Dec 2017 Link to this post

    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.
  7. pierre-jean
    pierre-jean avatar
    53 posts
    Member since:
    Apr 2011

    Posted 12 Dec 2017 Link to this post

    Thank your for your message

    Please excuse me I misread your previous message

    It all works fine.

    Best regards

    PJ

Back to Top