Sign in to follow this  
Followers 0
dickep

check all checkboxes in treeview

4 posts in this topic

How can I check on item in a treeview and have it check all the other boxes in that treeview?

I had MsCreatoR give me an example using a listview but I don't want any columns in the windows.

Thanks

E

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>
Opt("GuiOnEventMode", 1)

GUICreate("TreeView Check All", 460, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "MainEvents")

$TreeView = GUICtrlCreateTreeView(20, 20, 420, 260, BitOr($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES), _
    $WS_EX_DLGMODALFRAME+$WS_EX_CLIENTEDGE)

$SelAll_Item = GUICtrlCreateTreeViewItem("Select all", $TreeView)
GUICtrlSetOnEvent(-1, "MainEvents")
GUICtrlSetColor($SelAll_Item, 0xC0C0C0)

Global $TVItemsID_Array[11]
For $i = 1 To UBound($TVItemsID_Array)-1
    $TVItemsID_Array[$i] = GUICtrlCreateTreeViewItem("Item " & $i, $SelAll_Item)
    GUICtrlSetOnEvent(-1, "MainEvents")
Next

GUICtrlSetState($SelAll_Item, $GUI_EXPAND)

GUISetState()

While 1
    Sleep(10)
WEnd

Func MainEvents()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $SelAll_Item
            Local $State = $GUI_UNCHECKED

            If BitAND(GUICtrlRead($SelAll_Item), $GUI_CHECKED) Then
                $State = $GUI_CHECKED
                GUICtrlSetColor($SelAll_Item, 0x0)
            Else
                GUICtrlSetColor($SelAll_Item, 0xC0C0C0)
            EndIf

            For $a = 1 To UBound($TVItemsID_Array)-1
                GUICtrlSetState($TVItemsID_Array[$a], $State)
            Next
        Case Else
            If OneIsChecked() Then
                If AllIsChecked() Then
                    GUICtrlSetColor($SelAll_Item, 0x0)
                Else
                    GUICtrlSetColor($SelAll_Item, 0x696969)
                EndIf
                GUICtrlSetState($SelAll_Item, $GUI_CHECKED)
            Else
                GUICtrlSetColor($SelAll_Item, 0xC0C0C0)
                GUICtrlSetState($SelAll_Item, $GUI_UNCHECKED)
            EndIf
    EndSwitch
EndFunc

Func OneIsChecked()
    For $i = 1 To UBound($TVItemsID_Array)-1
        If BitAND(GUICtrlRead($TVItemsID_Array[$i]), $GUI_CHECKED) Then Return True
    Next
    
    Return False
EndFunc

Func AllIsChecked()
    For $i = 1 To UBound($TVItemsID_Array)-1
        If BitAND(GUICtrlRead($TVItemsID_Array[$i]), $GUI_UNCHECKED) Then Return False
    Next
    
    Return True
EndFunc

:)

but I don't want any columns in the windows.

Check the thread again.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

@MsCreatoR

Brilliant :)

I had quite a similar problem with a treeview (been using A3LTreeView) - trying to check all checkboxes (alot of checkboxes to check) and it didn't work properly. I've just decided to ask for help in this forum when I saw your post :)

Lucky me :)

Thank you


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Brilliant

Thanks :)

Here is an improved version, OnEvent Mode not used here:

#include <GUIConstants.au3>

Global $iTotal_Items = 10
Global $TVItemsID_Array[$iTotal_Items + 1]

GUICreate("TreeView Check All", 460, 300)

$TreeView = GUICtrlCreateTreeView(20, 20, 420, 260, _
    BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES), $WS_EX_DLGMODALFRAME + $WS_EX_CLIENTEDGE)

$SelAll_TVItem = GUICtrlCreateTreeViewItem("Select all", $TreeView)
GUICtrlSetColor($SelAll_TVItem, 0xC0C0C0)

For $i = 1 To $iTotal_Items
    $TVItemsID_Array[$i] = GUICtrlCreateTreeViewItem("Item " & $i, $SelAll_TVItem)
Next

GUICtrlSetState($SelAll_TVItem, $GUI_EXPAND)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $SelAll_TVItem
            Local $State = $GUI_UNCHECKED
            
            If BitAND(GUICtrlRead($SelAll_TVItem), $GUI_CHECKED) Then
                $State = $GUI_CHECKED
                GUICtrlSetColor($SelAll_TVItem, 0x0)
                GUICtrlSetState($SelAll_TVItem, $GUI_DEFBUTTON + $GUI_CHECKED)
            Else
                GUICtrlSetColor($SelAll_TVItem, 0xC0C0C0)
                GUICtrlSetState($SelAll_TVItem, $GUI_UNCHECKED)
            EndIf

            For $a = 1 To UBound($TVItemsID_Array) - 1
                GUICtrlSetState($TVItemsID_Array[$a], $State)
            Next
        Case $TVItemsID_Array[1] To $TVItemsID_Array[$iTotal_Items]
            
            
            If AllIsUnChecked() Then
                GUICtrlSetColor($SelAll_TVItem, 0xC0C0C0)
                GUICtrlSetState($SelAll_TVItem, $GUI_UNCHECKED)
            ElseIf AllIsChecked() Then
                GUICtrlSetColor($SelAll_TVItem, 0x0)
                GUICtrlSetState($SelAll_TVItem, $GUI_DEFBUTTON + $GUI_CHECKED)
            Else
                GUICtrlSetColor($SelAll_TVItem, 0x696969)
                GUICtrlSetState($SelAll_TVItem, $GUI_CHECKED)
            EndIf
    EndSwitch
WEnd

Func AllIsUnChecked()
    For $i = 1 To UBound($TVItemsID_Array) - 1
        If BitAND(GUICtrlRead($TVItemsID_Array[$i]), $GUI_CHECKED) Then Return False
    Next

    Return True
EndFunc

Func AllIsChecked()
    For $i = 1 To UBound($TVItemsID_Array) - 1
        If BitAND(GUICtrlRead($TVItemsID_Array[$i]), $GUI_UNCHECKED) Then Return False
    Next

    Return True
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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