I am using this code to drag and drop a treeview node to a different place on the same treeview. To my surprise, if I drag a node to a child node of the same node, it completely freezes on this line, because it removes itself. Where in the code can I detect if I am dragging a node onto a child of itself. Does not work!
NewParent.Nodes.Add(NodeToMove)
Full Code:
Private Sub TreeVault_DragDrop(ByVal sender As Object, ByVal e As Gizmox.WebGUI.Forms.DragEventArgs) Handles TreeVault.DragDrop
Dim sql As String
If e.GetType Is GetType(DragDropEventArgs) Then
Dim dd As DragDropEventArgs = e
If dd.Source IsNot Nothing _
AndAlso dd.SourceMember IsNot Nothing _
AndAlso dd.Source.GetType() Is GetType(Gizmox.WebGUI.Forms.TreeView) _
AndAlso dd.SourceMember.GetType() Is GetType(Gizmox.WebGUI.Forms.TreeNode) Then
Dim tn As TreeNode = dd.SourceMember
If dd.TargetMember IsNot Nothing And tn IsNot dd.TargetMember Then
MoveTreeNode(tn, dd.TargetMember)
End If
VaultFileTreeSet()
End If
End If
End Sub
Private Sub MoveTreeNode(ByVal NodeToMove As TreeNode, ByVal NewParent As TreeNode)
NodeToMove.Remove()
NewParent.Nodes.Add(NodeToMove)
TreeVault.Sort()
NewParent.Expand()
End Sub