treeview get all children only

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bish01
Posts: 96
Joined: 22 Feb 2016, 03:57

treeview get all children only

01 Mar 2017, 15:27

Hi.
I have been wrecking my brains last night and did not know how to properly do this but I am sure it is quite simple.

How do I get (only) all children item text under selected parent in treeview?

example:

Code: Select all

treeParent
  subItem1
  subItem2
    whatever1
    whatever2
  subItem3
So how do I get all "subItem" text (as list with `n delimiter) without getting "whatever" items or all the rest of parent items?
I looked in help and trying editing loop but I keep getting all tree items or none at all..

If I do not get chance to reply again I thank all who help in advance.
Cheers
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: treeview get all children only

01 Mar 2017, 16:02

I too have tried getting all items (not just children) from a treeview. specifically, ANY treeview (not just ahk ones).
I found a couple things (forgot where, it was years ago) but they were quite massive.

I can't help, but to clarify it for others:
do you need it for a treeview you made within ahk (gui,add,treeview) or another programs tree? (it makes a huge difference)
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
bish01
Posts: 96
Joined: 22 Feb 2016, 03:57

Re: treeview get all children only

01 Mar 2017, 16:35

Hi tidbit.
It is for ahk treeview I made and just need children of selected item. Not the whole tree.
Not sure how to loop correctly so it skips all but children (and skips childrens children) under selected parent.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: treeview get all children only

01 Mar 2017, 16:36

Try this:

Code: Select all

#NoEnv

    Gui, Add, Text,, Right click an item to get a list of all children:
    Gui, Add, TreeView, r12 gTV_onEvent AltSubmit
    Add_Tree(A_MyDocuments)
    Gui, Show

Return

GuiClose:
ExitApp



;-------------------------------------------------------------------------------
TV_onEvent: ; handle TreeView events
;-------------------------------------------------------------------------------
    If (A_GuiEvent == "RightClick") {

        Children := ""                              ; start empty
        TV_GetText(Parent, TV_Modify(A_EventInfo))  ; select parent
        ChildID := TV_GetChild(A_EventInfo)         ; first child

        While, TV_GetText(Child, ChildID) {         ; loop
            Children .= Child "`n"
            ChildID := TV_GetNext(ChildID)
        }
        MsgBox,, Children of %Parent%, %Children%   ; display
    }

Return



;-------------------------------------------------------------------------------
Add_Tree(Folder, ParentID = 0) { ; build tree from folder
;-------------------------------------------------------------------------------
    Loop, Files, %Folder%\*.*, DF
        Add_Tree(A_LoopFileFullPath, TV_Add(A_LoopFileName, ParentID))
}
I hope that helps.
bish01
Posts: 96
Joined: 22 Feb 2016, 03:57

Re: treeview get all children only

01 Mar 2017, 16:48

@wolf_II
Thank you that is exactly what I was after.
I was just doing wrong loops...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Draken, roeleboele and 363 guests