Jump to content
Sign in to follow this  

Check children on check Parent

Recommended Posts


Hi :P!

For a small project I use a TreeView with about 1300 Items, divided as 1 x 5 x 3 x 4 x 22. I would like it if each child automatically gets checked when I check a parent. For example, consider this setup:

-[ ]A

--|--[ ]Aa

--|--[ ]Ab

--|---|--[ ]Aba

--|---|--[ ]Abb

-[ ]B

Basically, when A is checked I want it's children Aa, Ab and their children, Aba and Abb to become checked as well. This can be accomplished by calling a function from the GUI's Main Loop to recursively walk through the entire tree (which therefore happens _a lot_), and comparing GUIGetMsg to the Item's Handle. If true, a recursive function to check it's children is called. This does work, but it's incredibly slow. I do not have variables for each Item cause the tree is also filled recursively out of 3 arrays. I do have variables for the 5 main 'parents'.

Anyways, I figured recursively checking the entire tree over and over again is simply a bad idea from the performance standpoint. Isn't there some kind of event triggered every time a check is put in a checkbox? I could check for the event and call my CheckAllChildren function, passing the Item's handle to it (which is hopefully sent when the the item's checkbox is checked). Any idea's?

I'm using the 12nov beta build.



Share this post

Link to post
Share on other sites

Just for the sake of people searching these forums for the solution to a similar problem I had; the key is in the _GUICtrlTreeView_HitTest function, available in the current Beta.

Check out this snippet (I'm using the OnEvent mode by the way, so I only recursively walk through the tree when a tree node is clicked).

For $Item = $Items_Start To $Items_Stop ; ==> Assign each Item common properties (font in Bold and assign CheckAction() to each)
    GUICtrlSetOnEvent ($Item, "CheckAction")
    GUICtrlSetState ($Item, $GUI_DEFBUTTON)


Func CheckAction()      
    $hit = _GUICtrlTreeView_HitTest($TreeView, MouseGetPos(0)-15, MouseGetPos(1)-15) ; ==> This -15 at both X & Y coordinates was needed to give correct HitTest results, wtf?
    If Not (@GUI_CTRLID = $Bergjes And $hit = 16) Or $hit = 64 Then ; ==> This fixed some odd problems I had with my root node sending wrong hittest flags when collapsed, you probably don't need it
        Case True
            CheckAllChildren($TreeView, @GUI_CTRLID)
        Case False
            CheckAllChildren($TreeView, @GUI_CTRLID, False)
EndFunc ; ==> CheckAction()
Edited by D4ni

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