Private Sub Form_Load() Dim node1 As Node, node2 As Node TreeView1.Nodes.Add , , "root", "root" Set node1 = TreeView1.Nodes.Add("root", tvwChild, "key1", "text1") set node2 =TreeView1.Nodes.Add("root", tvwChild, "key2", "text2") 'Set node2.Parent = node1.Parent Call swapnode(node2, node1) End Sub Private Sub swapnode(node1, node2) Dim tmpkey As String, tmptext As String tmpkey = node1.Key tmptext = node1.Text
TreeView1.Nodes.Add , , "root", "root"
Set node1 = TreeView1.Nodes.Add("root", tvwChild, "key1", "text1")
set node2 =TreeView1.Nodes.Add("root", tvwChild, "key2", "text2")
'Set node2.Parent = node1.Parent
Call swapnode(node2, node1)
End Sub
Private Sub swapnode(node1, node2)
Dim tmpkey As String, tmptext As String
tmpkey = node1.Key
tmptext = node1.Text
node1.Key = node2.Key & "_TMP"
node1.Text = node2.Text
node2.Key = tmpkey
node2.Text = tmptext
node1.Key = Left(node1.Key, Len(node1.Key) - 4)
End Sub