Jump to content
Sign in to follow this  
spudw2k

Treeview Checkboxes

Recommended Posts

spudw2k

-changed listview to treeview (my bad)

So I was having difficulties using the checkboxes in a treeview. I saw several posts that pointed to AU3lib. AU3lib is cool, and has some very neat-useful stuff but I did not like how it was handling my treeview (not to mention I couldn't get it to work). Here's some code that works with a treeview (w/ checkboxes) without using AU3lib.

#include <GuiTreeView.au3>
#include <Array.au3>

$arrComputers = _ArrayCreate("localhost","server1","workstation1","server2","workstation2")

$tGui = GUICreate("Computers in Domain",250,300,-1,-1)
$tFileMenu = GUICtrlCreateMenu("&Edit")
    $tSelectAll = GUICtrlCreateMenuItem("Select All" & @TAB & "CTRL + A",$tFileMenu)
    $tDeSelectAll = GUICtrlCreateMenuItem("DeSelect All" & @TAB & "CTRL + D",$tFileMenu)
$tTree = GUICtrlCreateTreeView(5,5,240,240,$TVS_CHECKBOXES)

Dim $tTreeArr[1]
For $i = 0 to UBound($arrComputers) - 1
    $tTreeArr[$i] = GUICtrlCreateTreeViewItem($arrComputers[$i],$tTree)
    ReDim $tTreeArr[$i + 2]
Next

GUISetState(@SW_SHOW,$tGui)

While 1

    $msg = GUIGetMsg()

    If $msg = $tSelectAll Then
        For $i = 0 to _GUICtrlTreeView_GetCount($tTree) - 1
            GUICtrlSetState($tTreeArr[$i],$GUI_CHECKED)
        Next
    EndIf

    If $msg = $tDeSelectAll Then
        For $i = 0 to _GUICtrlTreeView_GetCount($tTree) - 1
            GUICtrlSetState($tTreeArr[$i],$GUI_UNCHECKED)
        Next
    EndIf
        
;BitAnd(GUICtrlRead($tTreeArr[$i]),$GUI_CHECKED))    How to determine if checkbox is checked

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

Update: Changed getcount method to reflect new version of AutoIt 3.2.10.0

Edited by spudw2k

Share this post


Link to post
Share on other sites
spudw2k

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  

×