Checking Node of a TreView Control (1 Viewer)

gblack

Registered User.
Local time
Today, 21:28
Joined
Sep 18, 2002
Messages
632
So I have a Treeview control.

When the user clicks a node, I want to check to see if that's the last child in the hierarchy (i.e. the node has a parent, but is not a parent of any other node).

Is there any easy way to do this? I still haven't wrapped my pea-brain around this recursive logic.

I've read some online articles about iterating through TV Controls, but I just want a simple check to see if the node is the last child in the hierarchy...

Any ideas?

Respectfully,
Gary

PS. A little additional wrench to throw in here is that my hierarchy isn't uniform. Meaning some hierarchical threads might only go 5 levels down, whereas some might go 7 levels deep, some 8...
 
Last edited:

MarkK

bit cruncher
Local time
Today, 13:28
Joined
Mar 17, 2004
Messages
8,187
Check out the Children property of the MSComctlLib.Node, which...
Returns the number of child nodes a Node object has.
 

Minty

AWF VIP
Local time
Today, 21:28
Joined
Jul 26, 2013
Messages
10,375
You would need to query the current tree to see if the current node has a child record. It depends how your node values are stored / calculated?
 

gblack

Registered User.
Local time
Today, 21:28
Joined
Sep 18, 2002
Messages
632
MarkK... I think that's what I need... so if MSComctlLib.Node returns zero... then it would be the last node in the hierarchy... I guess...?
 

MarkK

bit cruncher
Local time
Today, 13:28
Joined
Mar 17, 2004
Messages
8,187
When the user clicks a node, I want to check to see if that's the last child in the hierarchy
No, you need to check the Node.Children property of the clicked node, so I would expect to see code that handles a Treeview.NodeClick event, like...

Code:
private withevents m_tvw as mscomctllib.treeview

private sub form_open(cancel as integer)
[COLOR="Green"]   'get a withevents object reference to the treeview in the control
   'so we can handle its events directly
[/COLOR]   set m_tvw = me.treeview0.object
[COLOR="Green"]   'presumably you run some kind of node creation routine here[/COLOR]
end sub

private sub m_tvw_NodeClick(nd as mscomctllib.node)
[COLOR="Green"]   'this event is raised by the treeview and gives us a reference
   'to the node that was clicked.[/COLOR]
   msgbox "the clicked node '" & nd.text & "' has " & nd.children & " children"
end sub
...so if we handle the Treeview.NodeClick() event, our handler is passed a reference to that clicked node. Then, we can very easily take a look at its properties, one of which is Children.

For tons more detailed info about these objects check them out in your object browser.
 

Users who are viewing this thread

Top Bottom