Sign in to follow this  
Followers 0
dazza

TreeView - checking a parent then checks the kids

4 posts in this topic

Using the code in the help files: _GUICtrlTreeView_Create.au3, I can detect when an item in the treeview is checked. However, I haven't a clue how to then check all the children (and grandchildren, great grandchildren et al) nodes below.

I humbly await the wisdom of AutoIT gurus.

Share this post


Link to post
Share on other sites



_GUICtrlTreeView_GetSelection and _GUICtrlTreeView_GetChildren

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

Ack. I've rummaged through these references; I still can't see how to do it :)

Someone please show me the code how to do it. It's probably quite simple--like me.

Ta

Share this post


Link to post
Share on other sites

Ack. I've rummaged through these references; I still can't see how to do it :)

Someone please show me the code how to do it. It's probably quite simple--like me.

Ta

This is a modified version of the example script for _GUICtrlTreeView_GetNextChild():
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>

Global $hItem[6], $hTreeView, $iRandomItem, $hRandomItem, $hFirstChild, $sFirstChild, $hNextChild, $sNextChild, $sMsg
Global $iStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS)

GUICreate("TreeView Get Next Child", 400, 300)

$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()

_GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 0 To UBound($hItem) - 1
    $hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x), $hTreeView)
    For $y = 0 To 2
        GUICtrlCreateTreeViewItem(StringFormat("[%02d-%02d] New Child Item", $x, $y), $hItem[$x])
    Next
Next
_GUICtrlTreeView_EndUpdate($hTreeView)

$iRandomItem = Random(0, UBound($hItem) - 1, 1)
$ctrlRandomItem = $hItem[$iRandomItem]
$sMsg &= "Randomly selected item = " & $iRandomItem & ", control ID = " & $ctrlRandomItem & @CRLF
$hFirstChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $ctrlRandomItem)
$sFirstChild = _GUICtrlTreeView_GetText($hTreeView, $hFirstChild)
$sMsg &= "First child handle = " & $hFirstChild & ", text = " & $sFirstChild & @CRLF
$hNextChild = _GUICtrlTreeView_GetNextChild($hTreeView, $hFirstChild)
$sNextChild = _GUICtrlTreeView_GetText($hTreeView, $hNextChild)
_GUICtrlTreeView_SelectItem($hTreeView, $hNextChild)
$sMsg &= "Next child handle = " & $hNextChild & ", text = " & $sNextChild
MsgBox(64, "_GuiCtrlTreeView_GetNextChild()", $sMsg)

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

You have my empathy if some of this is confusing. Some of the examples in the help file have extraneous stuff thrown in, and Control IDs and control handles are mixed where the parameters say you can only use one. ^_^

You want to get the control ID or handle for the parent item, then get the handle for the first child item, then a loop can get the next child/sibling until you have what you want. This demo only gets the first child and the next. You would have to add a loop to get them all.

Note _GuiCtrlTreeView_GetNextChild() is just an alias for _GuiCtrlTreeView_GetNextSibling(), added for consistency in the naming convention, I guess.

If that doesn't help, try to ask a more specific question about the part you don't understand.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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