Split TreeView function TV_GetChild() into two

Propose new features and changes
kidbit
Posts: 168
Joined: 02 Oct 2013, 16:05

Split TreeView function TV_GetChild() into two

18 Aug 2014, 04:37

Currently there's only TV_GetChild(), which being applied to the root element (TV_GetChild(0)) retrieves the topmost child in your tree.
And currently there's no easy way to start parsing a tree (or a branch) from the last child.

I suggest to split TV_GetChild() into at least two functions: TV_GetFirstChild() and TV_GetLastChild(), but a 3rd one TV_GetNthChild(N) would also be nice.
question := (2b) || !(2b) © Shakespeare.
just me
Posts: 9482
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Split TreeView function TV_GetChild() into two

18 Aug 2014, 06:49

kidbit wrote:And currently there's no easy way to start parsing a tree (or a branch) from the last child.
This may be caused by the fact, that the TVM_GETNEXTITEM message doesn't provide an appropriate option.

But:

Code: Select all

#NoEnv
Gui, Add, TreeView, w400 r10
P1 := TV_Add("First parent")
P1C1 := TV_Add("Parent 1's first child", P1)  ; Specify P1 to be this item's parent.
P2 := TV_Add("Second parent")
P2C1 := TV_Add("Parent 2's first child", P2)
P2C2 := TV_Add("Parent 2's second child", P2)
P2C3 := TV_Add("Parent 2's third child", P2)
P2C4 := TV_Add("Parent 2's fourth child", P2)
P2C5 := TV_Add("Parent 2's fifth child", P2)
P2C5C1 := TV_Add("Child 5's first child", P2C5)
TV_Modify(P2, "Expand")
Gui, Show, , TreeView Sample  ; Show the window and its TreeView.
Sleep, 500
TV_GetText(Text, TV_GetLastChild(P2))
MsgBox, 0, TV_GetLastChild(Parent 2), %Text%
TV_GetText(Text, TV_GetNthChild(P2, 3))
MsgBox, 0, TV_GetNthChild(Parent 2`, 3), %Text%
Return
GuiClose:  ; Exit the script when the user closes the TreeView's GUI window.
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
TV_GetLastChild(ParentItemID) {
   LastChild := 0
   IF (LastChild := TV_GetChild(ParentItemID))
      While (ID := TV_GetNext(LastChild))
         LastChild := ID
   Return LastChild
}
; ----------------------------------------------------------------------------------------------------------------------
TV_GetNthChild(ParentItemID, N) {
   NthChild := 0
   IF (N > 0) && (NthChild := TV_GetChild(ParentItemID))
      While (--N) && (NthChild := TV_GetNext(NthChild))
         Continue
   Return NthChild
}
*Edit: changed TV_GetNthChild()*
kidbit
Posts: 168
Joined: 02 Oct 2013, 16:05

Re: Split TreeView function TV_GetChild() into two

08 Sep 2014, 04:26

thanks, just me, for your functions.
It is actually a nice idea to use While loop like this, when all you need is to run a loop of 1 command and 1 if check after each iteration.
I will try to use that trick from now on everywhere possible :)
question := (2b) || !(2b) © Shakespeare.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 29 guests