Jump to content

Problem with checkboxes


FunThomas
 Share

Recommended Posts

Hi,

I have GUI with 4 checkboxes. When I check "checkCN1" all other checkboxes should be checked, but unchecking "checkCN2", "checkCN3" or "checkCN4" should uncheck "checkCN1". How I must construct the loop (code)? Please help.

#include <GUIConstantsEx.au3>

Opt("SendKeyDelay", 100)

Local $msg, $checkCN1, $checkCN2, $checkCN3, $checkCN4
GUICreate ( "Title", 100, 150)
$checkCN1 = GUICtrlCreateCheckbox("ALL", 20, 15, 110, 20)
$checkCN2 = GUICtrlCreateCheckbox("1", 20, 50, 80, 20)
$checkCN3 = GUICtrlCreateCheckbox("2", 20, 70, 100, 20)
$checkCN4 = GUICtrlCreateCheckbox("3", 20, 90, 120, 20)

Func check_all()
GUICtrlSetState($checkCN2, $GUI_CHECKED)
GUICtrlSetState($checkCN3, $GUI_CHECKED)
GUICtrlSetState($checkCN4, $GUI_CHECKED)
    EndFunc

GUISetState()

While 1
        $msg = GUIGetMsg()
        
        If GUICtrlRead($checkCN1) = $GUI_CHECKED Then check_all()
        
        Select
            Case $msg = $GUI_EVENT_CLOSE
                
                ExitLoop

        EndSelect
    WEnd
    
GUIDelete()
Edited by FunThomas
Link to comment
Share on other sites

  • Moderators

FunThomas,

Try this:

#include <GUIConstantsEx.au3>

Opt("SendKeyDelay", 100)

Global $msg, $checkCN1, $checkCN2, $checkCN3, $checkCN4

GUICreate("Title", 100, 150)
$checkCN1 = GUICtrlCreateCheckbox("ALL", 20, 15, 110, 20)
$checkCN2 = GUICtrlCreateCheckbox("1", 20, 50, 80, 20)
$checkCN3 = GUICtrlCreateCheckbox("2", 20, 70, 100, 20)
$checkCN4 = GUICtrlCreateCheckbox("3", 20, 90, 120, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $checkCN1
            If GUICtrlRead($checkCN1) = $GUI_CHECKED Then check_all()
        Case $checkCN2, $checkCN3, $checkCN4
            If Not (GUICtrlRead($checkCN2) = $GUI_CHECKED And GUICtrlRead($checkCN3) = $GUI_CHECKED And GUICtrlRead($checkCN4) = $GUI_CHECKED) _
                    Then GUICtrlSetState($checkCN1, $GUI_UNCHECKED)
    EndSwitch

WEnd

GUIDelete()

Func check_all()
    GUICtrlSetState($checkCN2, $GUI_CHECKED)
    GUICtrlSetState($checkCN3, $GUI_CHECKED)
    GUICtrlSetState($checkCN4, $GUI_CHECKED)
EndFunc   ;==>check_all

I changed the Select to a Switch - it is easier to write multiple element cases. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks!

Best regards, FunThomas

FunThomas,

Try this:

#include <GUIConstantsEx.au3>

Opt("SendKeyDelay", 100)

Global $msg, $checkCN1, $checkCN2, $checkCN3, $checkCN4

GUICreate("Title", 100, 150)
$checkCN1 = GUICtrlCreateCheckbox("ALL", 20, 15, 110, 20)
$checkCN2 = GUICtrlCreateCheckbox("1", 20, 50, 80, 20)
$checkCN3 = GUICtrlCreateCheckbox("2", 20, 70, 100, 20)
$checkCN4 = GUICtrlCreateCheckbox("3", 20, 90, 120, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $checkCN1
            If GUICtrlRead($checkCN1) = $GUI_CHECKED Then check_all()
        Case $checkCN2, $checkCN3, $checkCN4
            If Not (GUICtrlRead($checkCN2) = $GUI_CHECKED And GUICtrlRead($checkCN3) = $GUI_CHECKED And GUICtrlRead($checkCN4) = $GUI_CHECKED) _
                    Then GUICtrlSetState($checkCN1, $GUI_UNCHECKED)
    EndSwitch

WEnd

GUIDelete()

Func check_all()
    GUICtrlSetState($checkCN2, $GUI_CHECKED)
    GUICtrlSetState($checkCN3, $GUI_CHECKED)
    GUICtrlSetState($checkCN4, $GUI_CHECKED)
EndFunc   ;==>check_all

I changed the Select to a Switch - it is easier to write multiple element cases. :)

M23

Link to comment
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
 Share

  • Recently Browsing   0 members

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