7,765
社区成员
发帖
与我相关
我的任务
分享
Dim nodx As Node
Set 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