How to get radtreeview drag and drop event to handle the to get source and destination full path node ?

1 Answer 81 Views
Treeview
Aravind
Top achievements
Rank 2
Iron
Iron
Iron
Aravind asked on 22 May 2023, 04:07 AM | edited on 22 May 2023, 09:05 AM

Hi,
    1.  How to get radtreeview drag and drop event to handle to get source and destination full path node using vb.net. I tried but i can get both source and destination as same node. I provide treeview node sample structure.

Family
     ----Father
             ---Son1
             ---Son2
     ----Mother
             ---Son3
             ---Son4

 Here i drag and drop Son4 under the Son1, so i need to get source as Family/Mother/Son4 and destination as  Family/Father/Son1/Son4.

2. How to restrict to drop nodes in level 1(Family) and  level 3 (Son1,Son2,Son3,Son4), i need to move nodes Son1,Son2,Son3,Son4 under Father and Mother node, not to create child node under Son1,Son2,Son3,Son4, I mean move Son2 above Son1, same like Son4 move above Son3 and also move Son3 or 4 move to below Father node, same like Son1 or 2 move below Mother as child node.


Please reply asap.

Regards
Aravind

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 May 2023, 09:02 AM

Hi, Aravind,

RadTreeView handles the whole drag and drop operation by its TreeViewDragDropService

The following article is quite useful about handling all aspects of the drag and drop operation which I believe would be helpful for your scenario:

https://docs.telerik.com/devtools/winforms/controls/treeview/drag-and-drop/drag-and-drop-in-bound-mode 

Please give it a try and see how it would work on your end.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Aravind
Top achievements
Rank 2
Iron
Iron
Iron
commented on 22 May 2023, 09:16 AM | edited

Hi , i enabled Allow Drop properties as true, i can can arrange the nodes, but in vb.net code, i need to get source and destination node values ,Could you pls share sample code to project for this.

This is the code what i used to get source and destination, but both show as same node.


'In Form_Load event
   AddHandler RadTreeView1.MouseDown, AddressOf RadTreeView1_MouseDown
   AddHandler RadTreeView1.DragEnter, AddressOf RadTreeView1_DragEnter
   AddHandler RadTreeView1.DragDrop, AddressOf RadTreeView1_DragDrop


Private sourceNode As RadTreeNode
   
 Private Sub RadTreeView1_MouseDown(sender As Object, e As MouseEventArgs)
        Dim clickedNode As RadTreeNode = RadTreeView1.GetNodeAt(e.X, e.Y)

        If clickedNode IsNot Nothing Then
            sourceNode = clickedNode
            RadTreeView1.DoDragDrop(sourceNode, DragDropEffects.Move)
        End If
    End Sub

    Private Sub RadTreeView1_DragEnter(sender As Object, e As DragEventArgs)
        If e.Data.GetDataPresent(GetType(RadTreeNode)) Then
            e.Effect = DragDropEffects.Move
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

 Private Sub RadTreeView1_DragDrop(sender As Object, e As DragEventArgs)
        Dim targetNode As RadTreeNode = RadTreeView1.GetNodeAt(RadTreeView1.PointToClient(New Point(e.X, e.Y)))

        If targetNode IsNot Nothing AndAlso sourceNode IsNot Nothing Then
            ' Access the source and destination nodes
            Dim sourceFullPath As String = sourceNode.FullPath
            Dim destinationFullPath As String = targetNode.FullPath

            MessageBox.Show("Source Node: " & sourceFullPath & vbCrLf & "Destination Node: " & destinationFullPath)
        End If

        sourceNode = Nothing
    End Sub


Regards
Aravind

Dess | Tech Support Engineer, Principal
Telerik team
commented on 23 May 2023, 12:23 PM

Hi, Aravind,

Note that the MouseDownDragEnter and DragDrop events are relevant for the standard OLE drag-and-drop behavior in WinForms:

https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/walkthrough-performing-a-drag-and-drop-operation-in-windows-forms?view=netframeworkdesktop-4.8 

The previously referred article demonstrates how to use the TreeViewDragDropService which is specific for the Telerik UI for WinForms suite. I believe that it is a better option to use in your scenario. It is a derivative of the RadDragDropService which represents a service that manages drag and drop actions if the AllowDragDrop property for the respective control is set to true. Its convenient API gives you useful information about the target node. The RadDragOverEventArgs offers HitTarget which is usually the target visual TreeNodeElement.

The TreeNodeElement.Data property returns the associated data node - RadTreeNode which offers the FullPath property that you are looking for. I would highly encourage you have a look at the following article which offers C# and VB examples on all aspects of the drag and drop operation:

https://docs.telerik.com/devtools/winforms/controls/treeview/drag-and-drop/drag-and-drop-in-bound-mode   

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Tags
Treeview
Asked by
Aravind
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or