Jump to content
Sign in to follow this  

Check if any checkbox in a window is checked?

Recommended Posts

I have a gui window with a series of checkboxes created in an array as such:

$chkboxes[0] = GUICtrlCreateCheckbox($payers[0][0], -1 * $cellWidth, 0)
$left = 1
For $i = 1 to UBound($payers) -1 Step 1
Case $left = 3 ;Edit this number to change the number of columns of check boxes
  $chkboxes[$i] = Guictrlcreatecheckbox($payers[0][$i], -$left * $cellWidth, 0)
  $left = 1
Case else ;Adds checkboxes to existing row until row limit is reached
  $chkboxes[$i] = GUICtrlCreateCheckbox($payers[0][$i], 0, -1)
  $left += 1

The checkbox array takes the elements of another array as the data and arranges them in columns. The form I have takes input from two other input boxes as well as at least 1 or more of these checkboxes and generates output when a button is pressed. I'm trying to set up form validation to make sure the user can't press the generate button until both input boxes are filled in and at least one of the checkboxes is checked.

I use a Do.. While loop to check watch for various GUIGetMsg events such as when other buttons are pressed to perform an action. How can i add something to that loop that will check when ANY checkbox is added to enable/disable the generate button accordingly?

Share this post

Link to post
Share on other sites

I was thinking of a different way of doing it. With the example below, after checking one of the checkboxes, you must click somewhere in the gui to run a function that detects if any of the checkboxes are checked. The only problem with it is not being able to detect changes to the checkboxes directly.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Global $check1, $Checkbox1, $Checkbox2, $Checkbox3

GUIRegisterMsg($WM_LBUTTONDOWN, "_CheckForChange")

$Form1 = GUICreate("Form1", 294, 152)
$Button1 = GUICtrlCreateButton("Validate", 160, 48, 75, 25, 0)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 32, 32, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 32, 56, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Checkbox3", 32, 80, 97, 17)
GUICtrlSetState($Button1, $GUI_DISABLE)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $Button1
            MsgBox(0, "", $check1)

Func _CheckForChange()
    $check1 = GUICtrlRead($Checkbox1)
    $check2 = GUICtrlRead($Checkbox2)
    $check3 = GUICtrlRead($Checkbox3)
    If $check1 > 1 OR $check2 > 1 OR $check3 > 1 Then
        GUICtrlSetState($Button1, $GUI_ENABLE)

#include <ByteMe.au3>

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...