Dim NodeX As Node For Each NodeX In TreeView1.Nodes NodeX.Expanded = True Next NodeX ================================================================ 我是一个兵,来自老百姓。
感谢您使用微软产品。您可以如下例在Treeview中递归遍历鼠标点击的节点及其子节点:Private Sub Form_Load() Dim nodX As Node Set nodX = TreeView1.Nodes.Add(, , "R", "Root") Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C1", "Child 1") Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C2", "Child 2") Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C3", "Child 3") Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C4", "Child 4") Set nodX = TreeView1.Nodes.Add("C1", tvwChild, "C11", "Child 11") Set nodX = TreeView1.Nodes.Add("C1", tvwChild, "C12", "Child 12") Set nodX = TreeView1.Nodes.Add("C12", tvwChild, "C121", "Child 121") Set nodX = TreeView1.Nodes.Add("C1", tvwChild, "C13", "Child 13") Set nodX = TreeView1.Nodes.Add("C2", tvwChild, "C21", "Child 21") Set nodX = TreeView1.Nodes.Add("C2", tvwChild, "C22", "Child 22") nodX.EnsureVisible TreeView1.Style = tvwTreelinesText ' Style 4. TreeView1.BorderStyle = vbFixedSingle End SubPrivate Sub traval(nodex As Node)
Dim count As Integer Dim ChildNode As Node
count = nodex.Children
Debug.Print nodex.Text '或者对节点进行其他操作
If count > 0 Then
Set ChildNode = nodex.Child
traval ChildNode
For i = 2 To count Set ChildNode = ChildNode.Next
traval ChildNode Next
End IfEnd Sub Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node) traval Node
End Sub详细信息请参考: TreeView Control http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmctl198/html/vbobjtreeview.asp - 微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款 (http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。 为了为您创建更好的讨论环境,请参加我们的用户满意度调查 (http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
http://www.csdn.net/expert/topic/958/958179.xml?temp=.160351
For Each NodeX In TreeView1.Nodes
NodeX.Expanded = True
Next NodeX
================================================================
我是一个兵,来自老百姓。
Set nodX = TreeView1.Nodes.Add(, , "R", "Root")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C1", "Child 1")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C2", "Child 2")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C3", "Child 3")
Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C4", "Child 4")
Set nodX = TreeView1.Nodes.Add("C1", tvwChild, "C11", "Child 11")
Set nodX = TreeView1.Nodes.Add("C1", tvwChild, "C12", "Child 12")
Set nodX = TreeView1.Nodes.Add("C12", tvwChild, "C121", "Child 121")
Set nodX = TreeView1.Nodes.Add("C1", tvwChild, "C13", "Child 13")
Set nodX = TreeView1.Nodes.Add("C2", tvwChild, "C21", "Child 21")
Set nodX = TreeView1.Nodes.Add("C2", tvwChild, "C22", "Child 22") nodX.EnsureVisible
TreeView1.Style = tvwTreelinesText ' Style 4.
TreeView1.BorderStyle = vbFixedSingle
End SubPrivate Sub traval(nodex As Node)
Dim count As Integer
Dim ChildNode As Node
count = nodex.Children
Debug.Print nodex.Text '或者对节点进行其他操作
If count > 0 Then
Set ChildNode = nodex.Child
traval ChildNode
For i = 2 To count
Set ChildNode = ChildNode.Next
traval ChildNode
Next
End IfEnd Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node) traval Node
End Sub详细信息请参考:
TreeView Control
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmctl198/html/vbobjtreeview.asp
- 微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。