请高人指点vb6下遍历treeview的问题

guoguoququ 2013-12-25 09:23:33
Call TraverseNode(Treeview.NodeS, tkey) '调用递归
Public Sub TraverseNode(nodelist As NodeS, tkey As Double) '
Dim nodex As Node
For Each nodex In nodelist
If nodex.Key = "P" & Trim(tkey) Then '相同则展开
nodex.Selected = True
Exit Sub
End If
If nodex.children = 0 Then '判断子节点则调用
Else
Call TraverseNode(???, tkey)'???处不知道该如何传值
End If
Next
End Sub
难道从一开始我就传错值了吗?请高人指点,十万火急
...全文
190 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
guoguoququ 2013-12-25
  • 打赏
  • 举报
回复
OK,我明白了,根本不需要递归 If nodex.children = 0 Then '判断子节点则调用 Else Call TraverseNode(???, tkey)'???处不知道该如何传值 End If 这些代码删除掉就OK了
of123 2013-12-25
  • 打赏
  • 举报
回复
遍历根节点下各个子节点的例子(看最后一段):
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 
of123 2013-12-25
  • 打赏
  • 举报
回复
Treeview 控件的 Nodes 是包含各层父和子节点的。不要用分层的思路去处理。

7,765

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧