Sign in to follow this  
Followers 0
Tsukihime

Looping through children in a tree

6 posts in this topic

#1 ·  Posted (edited)

What's a clean way to loop through all of the children in a tree and print the structure out, using maybe spaces or hyphens to show the depth?

I'm thinking recursion..but is there a way to do it with just loops?

Edited by Tsukihime

Share this post


Link to post
Share on other sites



Hi.

What kind of tree are you talking about? File System - files - folders?

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Hi.

What kind of tree are you talking about? File System - files - folders?

Regards, Rudi.

Why does it matter?

Tsukihime,

Check out the _GUICtrlTreeView_Level() and _GUICtrlTreeView_GetNext() functions from the help file. They should be enough to get you started.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Why does it matter?

Because I imagined, he want's to process a filesystem structure tree.

You imagine, he's asking about...

_GUICtrlTreeView_Level()

_GUICtrlTreeView_GetNext()

But as he didn't answer neither your nor my question, it really doesn't matter :unsure:

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I was just going off of the OP, and it simply asked how to iterate through a treeview control. To me that doesn't denote specific usage to be tailored too. I prefer to the modular approach; If you start broad enough you could "write" something that could work for many "treeview" control scenarios.

edit:

I didn't ask a question either. Just gave my response.

Edited by spudw2k

Share this post


Link to post
Share on other sites

I ended up just using a recursive function cause using a loop was too complicated to get it to do what I wanted =/

Func getChildren($root, $depth)
    If _GUICtrlTreeView_GetChildren($hObjTree, $root) Then
        $child = _GUICtrlTreeView_GetFirstChild($hObjTree, $root)
        while $child
            getChildren($child, $depth + 1)
            $child = _GUICtrlTreeView_GetNextChild($hObjTree, $child)
        WEnd        
    EndIf
    return 
EndFunc

Hi.

What kind of tree are you talking about? File System - files - folders?

Regards, Rudi.

Nothing specific.

It is just a function that will loop through any arbitrary TreeView object.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0