遍历根节点下各个子节点的例子(看最后一段):Dim nodx As NodeSet TreeView1.ImageList = ImageList1'Add root Node Set nodx = TreeView1.Nodes.Add(, , "Root", "Root Node", "Closed")'Expand root node so we can see what's under it nodx.ExpandedImage = "Open" nodx.Expanded = True'Create a child node under the root node Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child1", "Child node 1", "Closed")'Expand this node so we can see what's under it nodx.ExpandedImage = "Open" nodx.Expanded = True'Create several more children Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child2", "Child node 2", "Leaf") Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child3", "Child node 3", "Leaf") Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child4", "Child node 4", "Leaf") Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child5", "Child node 5", "Leaf")'Create two child nodes under the first child node of root Set nodx = TreeView1.Nodes.Add("Child1", tvwChild, "Child1A", "Child node 1 A", "Leaf") Set nodx = TreeView1.Nodes.Add("Child1", tvwChild, "Child1B", "Child node 1 B", "Leaf")'Loop though each child of the root node Dim i As Long'Set nodx to the first child node of root. Set nodx = TreeView1.Nodes("Root").Child'Loop though each child nod assigning it to nodx For i = 1 To TreeView1.Nodes("Root").Children MsgBox nodx.Text Set nodx = nodx.Next Next
OK,我明白了,根本不需要递归 If nodex.children = 0 Then '判断子节点则调用 Else Call TraverseNode(???, tkey)'???处不知道该如何传值 End If 这些代码删除掉就OK了
Set nodx = TreeView1.Nodes.Add(, , "Root", "Root Node", "Closed")'Expand root node so we can see what's under it
nodx.ExpandedImage = "Open"
nodx.Expanded = True'Create a child node under the root node
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child1", "Child node 1", "Closed")'Expand this node so we can see what's under it
nodx.ExpandedImage = "Open"
nodx.Expanded = True'Create several more children
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child2", "Child node 2", "Leaf")
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child3", "Child node 3", "Leaf")
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child4", "Child node 4", "Leaf")
Set nodx = TreeView1.Nodes.Add("Root", tvwChild, "Child5", "Child node 5", "Leaf")'Create two child nodes under the first child node of root
Set nodx = TreeView1.Nodes.Add("Child1", tvwChild, "Child1A", "Child node 1 A", "Leaf")
Set nodx = TreeView1.Nodes.Add("Child1", tvwChild, "Child1B", "Child node 1 B", "Leaf")'Loop though each child of the root node
Dim i As Long'Set nodx to the first child node of root.
Set nodx = TreeView1.Nodes("Root").Child'Loop though each child nod assigning it to nodx
For i = 1 To TreeView1.Nodes("Root").Children
MsgBox nodx.Text
Set nodx = nodx.Next
Next
If nodex.children = 0 Then '判断子节点则调用
Else
Call TraverseNode(???, tkey)'???处不知道该如何传值
End If
这些代码删除掉就OK了