Treeview Control (Reacting to Drag and Drop Event):
Return to List
Private Sub Treeview1_DragDrop(Source As Control, x As Single, y As Single)
If optDragOn.Value = True Then
If Treeview1.DropHighlight Is Nothing Then
Set Treeview1.DropHighlight = Nothing
inDrag = False
Exit Sub
Else
strTempKey = Treeview1.DropHighlight.Key
' Key must demonstrate level 2 If Left(strTempKey, 1) <> "2" Then
MsgBox "Can only drop on Level 2!", vbOKOnly, "Drop Positioning Error"
Exit Sub' We don't want to drop on another level 3 or on a level 1 End If
If xNod = Treeview1.DropHighlight Then
MsgBox "Cannot drop on self!", vbOKOnly, "Drop Position Error"
Exit Sub' We don't want to drop over same item End If
' New Dad Text and GrandPa Text for Record change strDadText = Treeview1.DropHighlight.Text
strGrandPaText = Treeview1.DropHighlight.Parent.Text
strNodeKey = xNod.Key
strNodeText = xNod.Text
intOriginalParentIndex = xNod.Parent.Index
intOriginalGrandparentIndex = xNod.Parent.Parent.Index
intAuntsAndUncles = xNod.Parent.Parent.Children
intSiblings = xNod.Parent.Children - 1
If Treeview1.selecteditem.Index <> 1 Then
Treeview1.Nodes.Remove (Treeview1.selecteditem.Index)
If intSiblings = 0 Then' If no other children then remove the parent node Treeview1.Nodes.Remove (intOriginalParentIndex)
If intAuntsAndUncles = 1 Then' Dad's gone -- now SHOOT GRANDMA! Treeview1.Nodes.Remove (intOriginalGrandparentIndex)
End If
End If
Treeview1.Nodes.Add strTempKey, tvwChild, strNodeKey, strNodeText
EditTheRecords strDadText, strGrandPaText, strNodeKey
End If
Set Treeview1.DropHighlight = Nothing
inDrag = False
End If
End If
End Sub