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.
Split TreeView function TV_GetChild() into two
Split TreeView function TV_GetChild() into two
question := (2b) || !(2b) © Shakespeare.
Re: Split TreeView function TV_GetChild() into two
This may be caused by the fact, that the TVM_GETNEXTITEM message doesn't provide an appropriate option.kidbit wrote:And currently there's no easy way to start parsing a tree (or a branch) from the last child.
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
}
Re: Split TreeView function TV_GetChild() into two
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
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.
Who is online
Users browsing this forum: No registered users and 29 guests