J
Jonathan Brown
I'm trying to use the Microsoft Treeview Control Version 6.0 that comes as
part of the MSCommctlLib library. I've been able to create my heirarchical
structure following a how-to found here:
http://puremis.net/excel/code/080.shtml
I've set all my nodes to show checkboxes. I'm trying to uncheck all child
nodes if a parent node is unchecked. I know I have to iterate through the
tree some how and up until this point I've been able to get it to work down
to two levels, but I need it to go through all levels of any child nodes.
What's annoying is that this treeview control doesn't have a nodes collection
where I could just use a "for each node in selectednode.nodes" statement. If
that were the case then this would be easy.
Here's the code I have so far but it's not working:
Private Sub tvFilter_NodeCheck(ByVal node As MSComctlLib.node)
Dim treeNode As node
iterate:
Set treeNode = node.Child
For i = 1 To node.Children
treeNode.Checked = node.Checked
If treeNode.Children > 0 Then
Set node = treeNode
GoTo iterate:
End If
Set treeNode = treeNode.Next
Next i
end sub
I'm also being forced to use unstructured code by using the goto statement.
I tried creating a separate subprocedure that would call itself but I
couldn't get that working either. It looked something like:
Sub CheckAllChildNodes(ByVal treeNode As node, ByVal nodeChecked As Boolean)
Dim node As node
Set node = treeNode.Child
For i = 1 To treeNode.Children
node.Checked = nodeChecked
If node.Children > 0 Then
' If the current node has child nodes, call the
CheckAllChildsNodes method recursively.
Set treeNode = node.Child
CheckAllChildNodes treeNode, nodeChecked
End If
Next i
End Sub
Any ideas here would be greatly appreciated.
Thanks in advance.
Jonathan
part of the MSCommctlLib library. I've been able to create my heirarchical
structure following a how-to found here:
http://puremis.net/excel/code/080.shtml
I've set all my nodes to show checkboxes. I'm trying to uncheck all child
nodes if a parent node is unchecked. I know I have to iterate through the
tree some how and up until this point I've been able to get it to work down
to two levels, but I need it to go through all levels of any child nodes.
What's annoying is that this treeview control doesn't have a nodes collection
where I could just use a "for each node in selectednode.nodes" statement. If
that were the case then this would be easy.
Here's the code I have so far but it's not working:
Private Sub tvFilter_NodeCheck(ByVal node As MSComctlLib.node)
Dim treeNode As node
iterate:
Set treeNode = node.Child
For i = 1 To node.Children
treeNode.Checked = node.Checked
If treeNode.Children > 0 Then
Set node = treeNode
GoTo iterate:
End If
Set treeNode = treeNode.Next
Next i
end sub
I'm also being forced to use unstructured code by using the goto statement.
I tried creating a separate subprocedure that would call itself but I
couldn't get that working either. It looked something like:
Sub CheckAllChildNodes(ByVal treeNode As node, ByVal nodeChecked As Boolean)
Dim node As node
Set node = treeNode.Child
For i = 1 To treeNode.Children
node.Checked = nodeChecked
If node.Children > 0 Then
' If the current node has child nodes, call the
CheckAllChildsNodes method recursively.
Set treeNode = node.Child
CheckAllChildNodes treeNode, nodeChecked
End If
Next i
End Sub
Any ideas here would be greatly appreciated.
Thanks in advance.
Jonathan