Sign in to follow this  
Followers 0
MattHiggs

List box item selection trigger event

4 posts in this topic

Hello All,

I am trying to code a for which contains 2 list box controls that, and I would like to make them behave like single control: when none of the items in either of the list boxes is selected, all of the other controls in the form will be hidden from view.  However, if even a single item in either box is selected, the  other controls will appear, but will disappear again only if none of the items in both lists are selected.  I have code written up which, unfortunately, continues to read that there are selected items in the two lists despite the fact that there aren't, so I can't get the other controls to disappear when none of the items in either box are selected.

$Form3 = GUICreate("References", 394, 397, 228, 222, -1, -1, $Form1_1)
$too = Int ( IniRead ( @ScriptDir & "\login.ini", "Hold Num", "Reference Number", "Problem" ) )
$List4 = GUICtrlCreateList("", 48, 48, 281, 188, BitOR($GUI_SS_DEFAULT_LIST,$LBS_MULTIPLESEL,$LBS_HASSTRINGS,$LBS_DISABLENOSCROLL,$WS_HSCROLL))
For $prep = 1 To $too Step 1
    GUICtrlSetData ( -1, IniRead ( @ScriptDir & "\login.ini", "Reference " & $prep, "Name", "Null" ) )
Next
$Checkbox35 = GUICtrlCreateCheckbox("Company?", 48, 248, 73, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
$Checkbox36 = GUICtrlCreateCheckbox("Title?", 48, 272, 49, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
$Checkbox37 = GUICtrlCreateCheckbox("Phone?", 136, 272, 57, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
$Checkbox38 = GUICtrlCreateCheckbox("Relationship?", 128, 248, 97, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
$Checkbox39 = GUICtrlCreateCheckbox("Email?", 248, 272, 57, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
$Checkbox40 = GUICtrlCreateCheckbox("Years known?", 240, 248, 89, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
$Button21 = GUICtrlCreateButton("&OK", 80, 328, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetCursor (-1, 0)
$Button22 = GUICtrlCreateButton("&Cancel", 192, 328, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetCursor (-1, 0)
$Label4 = GUICtrlCreateLabel("References", 136, 8, 101, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUISetState ( $Form3, @SW_SHOW )

While 1
$nmsg = GUIGetMsg ()
Switch $nmsg
    Case $GUI_EVENT_CLOSE
                    _GUICtrlListBox_ResetContent ( $List2 )

                    _GUICtrlListBox_ResetContent ( $List3 )
                    For $rer = 1 To $thee Step 1
                        If IniRead ( @ScriptDir & "\login.ini", "Education history " & $rer, "Education Level", "null" ) == "College" Then
                            GUICtrlSetData ( $List3, IniRead ( @ScriptDir & "\login.ini", "Education history " & $rer, "Name", "null" ) )
                        Else
                            GUICtrlSetData ( $List2, IniRead ( @ScriptDir & "\login.ini", "Education history " & $rer, "Name", "null" ) )
                        EndIf
                    Next

                    GUICtrlSetState ( $Checkbox14, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Checkbox14, $GUI_HIDE )
                    GUICtrlSetState ( $Checkbox14, $GUI_DISABLE )
                    GUICtrlSetState ( $Checkbox15, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Checkbox15, $GUI_HIDE)
                    GUICtrlSetState ( $Checkbox15, $GUI_DISABLE )
                    GUICtrlSetState ( $Checkbox16, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Checkbox16, $GUI_HIDE )
                    GUICtrlSetState ( $Checkbox16, $GUI_DISABLE )
                    GUICtrlSetState ( $Checkbox17, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Checkbox17, $GUI_HIDE )
                    GUICtrlSetState ( $Checkbox17, $GUI_DISABLE )
                    GUICtrlSetState ( $Checkbox18, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Checkbox18, $GUI_HIDE )
                    GUICtrlSetState ( $Checkbox18, $GUI_DISABLE )
                    GUICtrlSetState ( $Checkbox19, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Checkbox19, $GUI_HIDE )
                    GUICtrlSetState ( $Checkbox19, $GUI_DISABLE )
                    GUICtrlSetState ( $Checkbox20, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Checkbox20, $GUI_HIDE )
                    GUICtrlSetState ( $Checkbox20, $GUI_DISABLE )
                    GUICtrlSetState ( $Checkbox21, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Checkbox21, $GUI_HIDE )
                    GUICtrlSetState ( $Checkbox21, $GUI_DISABLE )
                    GUICtrlSetState ( $Radio8, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Radio8, $GUI_HIDE )
                    GUICtrlSetState ( $Radio8, $GUI_DISABLE )
                    GUICtrlSetState ( $Radio9, $GUI_UNCHECKED )
                    GUICtrlSetState ( $Radio9, $GUI_HIDE )
                    GUICtrlSetState ( $Radio9, $GUI_DISABLE )
                    GUICtrlSetState ( $Button14, $GUI_HIDE )
                    GUICtrlSetState ( $Button14, $GUI_DISABLE )
                    GUICtrlSetState ( $Group1, $GUI_HIDE )
                    GUICtrlSetState ( $Group1, $GUI_DISABLE )
                    GUISetState ( @SW_HIDE, $Form3_1 )
                    GUISwitch ( $Form1_1 )
                    GUICtrlSetState ( $Checkbox8, $GUI_UNCHECKED )
                    GUISetState ( @SW_SHOW, $Form1_1 )
                Case $List2
                    If _GUICtrlListBox_GetSelCount ( $List2 ) = -1 And _GUICtrlListBox_GetSelCount ( $List3 ) = -1 Then
                        GUICtrlSetState ( $Checkbox14, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox14, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox14, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox15, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox15, $GUI_HIDE)
                        GUICtrlSetState ( $Checkbox15, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox16, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox16, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox16, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox17, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox17, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox17, $GUI_DISABLE )
                        GUICtrlSetState ( $Button14, $GUI_HIDE )
                        GUICtrlSetState ( $Button14, $GUI_DISABLE )
                    Else
                        GUICtrlSetState ( $Checkbox14, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox14, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox15, $GUI_SHOW)
                        GUICtrlSetState ( $Checkbox15, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox16, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox16, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox17, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox17, $GUI_ENABLE )
                        GUICtrlSetState ( $Button14, $GUI_SHOW )
                        GUICtrlSetState ( $Button14, $GUI_ENABLE )

                    EndIf

                Case $List3
                    If _GUICtrlListBox_GetSelCount ( $List2 ) = -1 And _GUICtrlListBox_GetSelCount ( $List3 ) = -1 Then
                        GUICtrlSetState ( $Checkbox14, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox14, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox14, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox15, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox15, $GUI_HIDE)
                        GUICtrlSetState ( $Checkbox15, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox16, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox16, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox16, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox17, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox17, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox17, $GUI_DISABLE )
                        GUICtrlSetState ( $Button14, $GUI_HIDE )
                        GUICtrlSetState ( $Button14, $GUI_DISABLE )

                    Else
                        GUICtrlSetState ( $Checkbox14, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox14, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox15, $GUI_SHOW)
                        GUICtrlSetState ( $Checkbox15, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox16, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox16, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox17, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox17, $GUI_ENABLE )
                        GUICtrlSetState ( $Button14, $GUI_SHOW )
                        GUICtrlSetState ( $Button14, $GUI_ENABLE )
                    EndIf
                Case $Checkbox14
                    If GUICtrlRead ( $Checkbox14 ) = 1 Then
                        GUICtrlSetState ( $Radio8, $GUI_ENABLE )
                        GUICtrlSetState ( $Radio8, $GUI_SHOW )
                        GUICtrlSetState ( $Radio9, $GUI_ENABLE )
                        GUICtrlSetState ( $Radio9, $GUI_SHOW )
                    Else
                        GUICtrlSetState ( $Group1, $GUI_DISABLE )
                        GUICtrlSetState ( $Group1, $GUI_HIDE )
                        GUICtrlSetState ( $Radio8, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Radio8, $GUI_DISABLE )
                        GUICtrlSetState ( $Radio8, $GUI_HIDE )
                        GUICtrlSetState ( $Radio9, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Radio9, $GUI_DISABLE )
                        GUICtrlSetState ( $Radio9, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox18, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox18, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox18, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox19, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox19, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox19, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox20, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox20, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox20, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox21, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox21, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox21, $GUI_HIDE )
                    EndIf
                Case $Checkbox15

                Case $Checkbox16

                Case $Checkbox17
                Case $Radio8
                    If GUICtrlRead ( $Radio8 ) = 1 Then
                        GUICtrlSetState ( $Group1, $GUI_DISABLE )
                        GUICtrlSetState ( $Group1, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox18, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox18, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox18, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox19, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox19, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox19, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox20, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox20, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox20, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox21, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox21, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox21, $GUI_HIDE )
                    EndIf
                Case $Radio9
                    If GUICtrlRead ( $Radio9 ) = 1 Then
                        GUICtrlSetState ( $Group1, $GUI_ENABLE )
                        GUICtrlSetState ( $Group1, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox18, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox18, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox19, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox19, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox20, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox20, $GUI_SHOW )
                        GUICtrlSetState ( $Checkbox21, $GUI_ENABLE )
                        GUICtrlSetState ( $Checkbox21, $GUI_SHOW )
                    Else
                        GUICtrlSetState ( $Group1, $GUI_DISABLE )
                        GUICtrlSetState ( $Group1, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox18, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox18, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox18, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox19, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox19, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox19, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox20, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox20, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox20, $GUI_HIDE )
                        GUICtrlSetState ( $Checkbox21, $GUI_UNCHECKED )
                        GUICtrlSetState ( $Checkbox21, $GUI_DISABLE )
                        GUICtrlSetState ( $Checkbox21, $GUI_HIDE )
                    EndIf
                Case $Checkbox18
                    If GUICtrlRead ( $Checkbox18 ) = 1 And GUICtrlRead ( $Radio9 ) = 1 Then
                        $street = True
                    Else
                        $street = False
                    EndIf

                Case $Checkbox19
                    If GUICtrlRead ( $Checkbox19 ) = 1 And GUICtrlRead ( $Radio9 ) = 1 Then
                        $city = True
                    Else
                        $city = False
                    EndIf

                Case $Checkbox20
                    If GUICtrlRead ( $Checkbox20 ) = 1 And GUICtrlRead ( $Radio9 ) = 1 Then
                        $state = True
                    Else
                        $state = False
                    EndIf

                Case $Checkbox21
                    If GUICtrlRead ( $Checkbox21 ) = 1 And GUICtrlRead ( $Radio9 ) = 1 Then
                        $zip = True
                    Else
                        $zip = False
                    EndIf

                Case $Button14
                    $edlist = _GUICtrlListBox_GetSelItemsText ( $List2 )
                    $edlist2 = _GUICtrlListBox_GetSelItemsText ( $List3 )
                    $tota = $edlist[0] + $edlist2[0]
                    $storehere = 0
                    Local $edarray[$tota]
                    For $yre = 1 To Int (IniRead ( @ScriptDir & "\login.ini", "Hold Num", "Education number", "null" ) ) Step 1
                        For $try = 1 To $edlist[0] Step 1
                            If StringCompare ( IniRead ( @ScriptDir & "\login.ini", "Education history " & $yre, "Name", "NULL" ), $edlist[$try] ) = 0 Then
                                $edarray[$storehere] = "Education history " & $yre
                                $storehere = $storehere + 1
                            EndIf
                        Next
                        For $try = 1 To $edlist2[0] Step 1
                            If StringCompare ( IniRead ( @ScriptDir & "\login.ini", "Education history " & $yre, "Name", "NULL" ), $edlist2[$try] ) = 0 Then
                                $edarray[$storehere] = "Education history " & $yre
                                $storehere = $storehere + 1
                            EndIf
                        Next
                    Next
                    For $hear = 0 To $tota - 1 Step 1
                        $rab = ""
                        If IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "Education Level", "null" ) == "College" Then
                            $rab = "College name"
                        Else
                            $rab = "High School name"
                        EndIf
                        $Listinput49 = GUICtrlCreateListViewItem ( $rab & "|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "Name", "Null" ), $ListView1 )
                        GUICtrlSetFont ( -1, 12, $FW_BOLD )
                        If GUICtrlRead ( $Checkbox14 ) = 1 Then
                            If GUICtrlRead ( $Checkbox14 ) = 1 And GUICtrlRead ( $Radio8 ) = 1 Then
                                $Listinput48 = GUICtrlCreateListViewItem ( "Street address|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "Street Address", "null" ), $ListView1 )
                                $Listinput49 = GUICtrlCreateListViewItem ( "City|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "City", "null" ), $ListView1 )
                                $Listinput50 = GUICtrlCreateListViewItem ( "State|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "State", "null" ), $ListView1 )
                                $Listinput51 = GUICtrlCreateListViewItem ( "Zip code|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "Zip code", "null" ), $ListView1 )
                            ElseIf GUICtrlRead ( $Checkbox14 ) = 1 And GUICtrlRead ( $Radio9 ) = 1 Then
                                If GUICtrlRead ( $Checkbox18 ) = 1 Then
                                    $Listinput52 = GUICtrlCreateListViewItem ( "Street address|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "Street Address", "null" ), $ListView1 )
                                EndIf
                                If GUICtrlRead ( $Checkbox19 ) = 1 Then
                                    $Listinput53 = GUICtrlCreateListViewItem ( "City|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "City", "null" ), $ListView1 )
                                EndIf
                                If GUICtrlRead ( $Checkbox20 ) = 1 Then
                                    $Listinput54 = GUICtrlCreateListViewItem ( "State|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "State", "null" ), $ListView1 )
                                EndIf
                                If GUICtrlRead ( $Checkbox21 ) = 1 Then
                                    $Listinput55 = GUICtrlCreateListViewItem ( "Zip code|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "Zip code", "null" ), $ListView1 )
                                EndIf
                            EndIf
                        EndIf
                        If GUICtrlRead ( $Checkbox15 ) = 1 Then
                            $Listinput56 = GUICtrlCreateListViewItem ( "Phone number|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "Phone number", "Null" ), $ListView1 )
                        EndIf
                        If GUICtrlRead ( $Checkbox16 ) = 1 Then
                            $Listinput57 = GUICtrlCreateListViewItem ( "GPA|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "GPA", "Null" ), $ListView1 )
                        EndIf
                        If GUICtrlRead ( $Checkbox17 ) = 1 Then
                            $Listinput58 = GUICtrlCreateListViewItem ( "Degree|" & IniRead ( @ScriptDir & "\login.ini", $edarray[$hear], "Degree", "Null" ), $ListView1 )
                        EndIf
                    Next


EndSwitch
WEnd

BTW, this project is one I have been working on for a while, with many other Windows and controls, so if you are confused as to why this snipet references objects not declared, that is why.  Assume that everything outside the context of this code works correctly.  Any advice would be awesome

Share this post


Link to post
Share on other sites



Not a big listbox professor, but here is simple example of using Adlib method...

#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>

AdlibRegister(_Test, 1000)

$hGUI = GUICreate("Test", 500, 500)

$cList_1 = GUICtrlCreateList("", 10, 10, 200, 200, $LBS_EXTENDEDSEL)

GUICtrlSetData($cList_1, "1|2|3|4")

$cList_2 = GUICtrlCreateList("", 260, 10, 200, 200, $LBS_EXTENDEDSEL)

GUICtrlSetData($cList_2, "5|6|7|8")

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func _Test()
    If _GUICtrlListBox_GetSelCount($cList_1) + _GUICtrlListBox_GetSelCount($cList_2) > 0 Then
        ConsoleWrite("selected" & @LF)
        ; do whatever to unhide
        Return
    EndIf
    ConsoleWrite("not selected" & @LF)
    ; do whatever to hide
EndFunc   ;==>_Test

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Thank you for your replies.  You have been a great help.  If I could ask another, semi-related question, does anybody know of any good/available resources for someone with an intermediate understanding of scripting/coding who is trying to learn more about scripting/development in Windows?

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