timdecker

Disable buttons if checkbox not checked

5 posts in this topic

I would like to have the bottons only enabled if the checkboxes are checked. Below is the code I am using, the comments between the #CS and #CE is what I was trying to get to work...

#include <file.au3>
#include <GUICONSTANTS.au3>

Global $a_csv
$s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)")
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    Exit
Else
    _FileReadToArray($s_Path, $a_csv)
    GUICreate("CSV Listview", 900, 450, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 600, 210)
    $checkboxName = StringSplit($a_csv[1], ",")
    $iCount = $checkboxName[0]

    Global $aCheck[$iCount + 1]
    Global $mapColumn[$iCount + 1]
    $nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30)
    $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30)
    $button_enabled = 1

    For $j = 1 To $iCount
        ; Store controIDs of the checkboxes
        $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30)
        $mapColumn[$j] = GUICtrlCreateButton("Map " & '"'  & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30)
        GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED)
        GUICtrlSetState($mapColumn[$j], $GUI_DISABLE)
    Next
#cs
While 1
                            if BitAnd(GUICtrlRead($aCheck[$j]),$GUI_UNCHECKED) = $GUI_UNCHECKED Then

                                GUICtrlSetState($mapColumn[$j], $GUI_DISABLE)
                                $button_enabled = 0

                            ElseIf $button_enabled = 0 And BitAnd(GUICtrlRead($aCheck[$j]),$GUI_UNCHECKED) = $GUI_CHECKED Then

                                    GUICtrlSetState($mapColumn[$j], $GUI_ENABLE)
                                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : GUICtrlSetState($mapColumn[$j], $GUI_ENABLE) = ' & GUICtrlSetState($mapColumn[$j], $GUI_ENABLE) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                                    $button_enabled = 1

                            EndIf
                            wend
#ce
    GUISetState()

    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next

EndIf


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
Exit

Share this post


Link to post
Share on other sites



Do you want something like this below?

#include <GUIConstantsEx.au3>

Global $iNumOfCtrls=5
Global $aChkBox[$iNumOfCtrls], $aBtn[$iNumOfCtrls]

$hMain=GUICreate("test")
For $i=0 To $iNumOfCtrls-1
    $aChkBox[$i]=GUICtrlCreateCheckbox("CheckBox " & $i,10,10+$i*22,200,22)
    $aBtn[$i]=GUICtrlCreateButton("Button " & $i,10+200+40,10+$i*22,200,22)
    GUICtrlSetState(-1,$GUI_DISABLE)
Next
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    For $i=0 To $iNumOfCtrls-1
        If  BitAND(GUICtrlGetState($aBtn[$i]),$GUI_DISABLE) And BitAND(GUICtrlRead($aChkBox[$i]),$GUI_CHECKED) Then
            GUICtrlSetState($aBtn[$i],$GUI_ENABLE)
            ExitLoop
        ElseIf BitAND(GUICtrlGetState($aBtn[$i]),$GUI_ENABLE) And BitAND(GUICtrlRead($aChkBox[$i]),$GUI_UNCHECKED) Then
            GUICtrlSetState($aBtn[$i],$GUI_DISABLE)
            ExitLoop
        EndIf
    Next
WEnd

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

timdecker,

I would do it like this:

#include <file.au3>
#include <GUIConstantsEx.au3>

Global $a_csv[2] = [3, "Col 1,Col 2,Col 3"]
;$s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)")
;If @error Then
;   MsgBox(4096, "", "No File(s) chosen")
;    Exit
;Else
    ;_FileReadToArray($s_Path, $a_csv)
    GUICreate("CSV Listview", 900, 450, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 600, 210)
    $checkboxName = StringSplit($a_csv[1], ",")
    $iCount = $checkboxName[0]

    Global $aCheck[$iCount + 1]
    Global $mapColumn[$iCount + 1]
    $nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30)
    $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30)
    $button_enabled = 1

    For $j = 1 To $iCount
        ; Store controIDs of the checkboxes
        $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30)
        $mapColumn[$j] = GUICtrlCreateButton("Map " & '"'  & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30)
        GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED)
        GUICtrlSetState($mapColumn[$j], $GUI_DISABLE)
    Next

    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next

;EndIf

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            For $i = 1 To $iCount
                If $msg = $aCheck[$i] Then
                    If GUICtrlRead($msg) = 1 Then
                        GUICtrlSetState($mapColumn[$i], $GUI_ENABLE)
                    Else
                        GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                    EndIf
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd
Exit
Please ask if you have any questions. :)

M23

Edited by Melba23
Typo
1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

@ahmet and @Melba23, thank you both for your response. I was able to get both to work as I would like.

Is there an advantage to using one over the other?

Thanks again!

Share this post


Link to post
Share on other sites

timdecker,

My version only runs when a control is actioned - the other version runs through all the controls on every pass through the loop. So I would suggest that my version is better - but then you would expect me to say that anyway. ;)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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