LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Iterate through treeview nodes

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 he
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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA croaks on Nodes.Clear if TreeView is *not* Visible. [email protected] Excel Programming 1 August 24th 08 12:54 AM
TreeView Control V - 6.0 - Drag-Drop Nodes mecg96 Excel Programming 6 March 8th 08 08:34 PM
Adding nodes to treeview John Excel Programming 3 December 1st 04 09:07 PM
treeview add nodes Serkan[_2_] Excel Programming 3 October 3rd 03 09:55 AM
TreeView: add more than one node to nodes collection Peter[_25_] Excel Programming 3 September 5th 03 12:15 PM


All times are GMT +1. The time now is 08:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"