[RESOLVED] TreeView Drag&Drop nodes
Please, I'm on the verge of pulling my hair out. What am I doing wrong?
Basically I need to be able to drag nodes between different parents within a treeview.
The treeview simply does not acctept the Drop and DragDrop event is not firing.
I wrote an example code with the same effect (node drag is not working). Wham am I missing?
Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim root As New TreeNode("ROOT")
root.Nodes.Add("Child1")
root.Nodes.Add("Child2")
root.Nodes.Add("Child3")
TreeView1.AllowDrop = True
TreeView1.Nodes.Add(root)
End Sub
Private Sub TreeView1_DragDrop(sender As Object, e As DragEventArgs) Handles TreeView1.DragDrop
End Sub
Private Sub TreeView1_ItemDrag(sender As Object, e As ItemDragEventArgs) Handles TreeView1.ItemDrag
DoDragDrop(e.Item, DragDropEffects.Move)
End Sub
End Class
Re: TreeView Drag&Drop nodes
Have you tried this sample?
Re: TreeView Drag&Drop nodes
This one works, but I need to drag nodes within a single Treeview. I can't understand why this isn't working.
Re: TreeView Drag&Drop nodes
Got it working, even though I still don't understand why this was necessary. All I needed was to add the DragEnter event handler:
Code:
Private Sub TreeView1_DragEnter(sender As Object, e As DragEventArgs) Handles TreeView1.DragEnter
e.Effect = DragDropEffects.Move
End Sub
Re: [RESOLVED] TreeView Drag&Drop nodes
I did a project heavy in this type of moving nodes between trees and around on the same trees. I don't have that code handy but use the example that Arnoutdv gave and remember you really aren't just changing the parent of the node but instead notice in the TreeView1.DragDrop event in the example they add a Clone of the node and then remove the actual node. A node cannot belong to 2 parents at the same time. Nor can it belong to 2 trees, though not your problem here.
Hope that helps.