Jump to content

Recommended Posts

Posted

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

Posted

#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

:)

  Quote

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

Check the thread again.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

@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 :)

Posted

  Quote

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

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...