Private Sub Form_Load() For i = 1 To 10 TreeView1.Nodes.Add , , , "main" + Str(i) For j = 1 To 10 TreeView1.Nodes.Add i, 4, , "sub" + Str(i) Next Next End SubPrivate Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node) Dim N As Integer Dim intNodPos As Integer intNodPos = 0 N = Node.FirstSibling.Index Do While N <> Node.LastSibling.Index intNodPos = intNodPos + 1 If N = Node.Index Then MsgBox ("the position of node that clicked is " + Str(intNodPos)) Exit Do End If N = TreeView1.Nodes(N).Next.Index If N = Node.LastSibling.Index Then MsgBox ("the position of node that clicked is " + Str(intNodPos + 1)) End If
中间是用“/”分割的,你也可以自己定义
For i = 1 To 10
TreeView1.Nodes.Add , , , "main" + Str(i)
For j = 1 To 10
TreeView1.Nodes.Add i, 4, , "sub" + Str(i)
Next
Next
End SubPrivate Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Dim N As Integer
Dim intNodPos As Integer
intNodPos = 0
N = Node.FirstSibling.Index
Do While N <> Node.LastSibling.Index
intNodPos = intNodPos + 1
If N = Node.Index Then
MsgBox ("the position of node that clicked is " + Str(intNodPos))
Exit Do
End If
N = TreeView1.Nodes(N).Next.Index
If N = Node.LastSibling.Index Then
MsgBox ("the position of node that clicked is " + Str(intNodPos + 1))
End If
Loop
End Sub