Sign in to follow this  
Followers 0
strik3r0475

Combo Selection

4 posts in this topic

I want to select an item in the first combo box and then use that to determine what will be available

for selection in the second combo box.

For example, the first como box has a list of states. You select a state and depending what state

you select, different cities or zip codes for the selected state will be available in the second box.

#include <GuiConstants.au3>
GUICreate("State And Zip", 300, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$Combo_1 = GUICtrlCreateCombo("Choose Your State", 30, 30, 240, 21, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData(-1, "Alabama")
GUICtrlSetData(-1, "Alaska")
GUICtrlSetData(-1, "Arizona")
GUICtrlSetData(-1, "Arkansas")
GUICtrlSetData(-1, "California")
GUICtrlSetData(-1, "Colorado")
GUICtrlSetData(-1, "Connecticut")
GUICtrlSetData(-1, "Delaware")
GUICtrlSetData(-1, "District of Columbia")
GUICtrlSetData(-1, "Florida")
GUICtrlSetData(-1, "Georgia")
GUICtrlSetData(-1, "Hawaii")
GUICtrlSetData(-1, "Idaho")
GUICtrlSetData(-1, "Illinois")
GUICtrlSetData(-1, "Indiana")
GUICtrlSetData(-1, "Iowa")
GUICtrlSetData(-1, "Kansas")
GUICtrlSetData(-1, "Kentucky")
GUICtrlSetData(-1, "Louisiana")
GUICtrlSetData(-1, "Maine")
GUICtrlSetData(-1, "Maryland")
GUICtrlSetData(-1, "Massachusetts")
GUICtrlSetData(-1, "Michigan")
GUICtrlSetData(-1, "Minnesota")
GUICtrlSetData(-1, "Mississippi")
GUICtrlSetData(-1, "Missouri")
GUICtrlSetData(-1, "Montana")
GUICtrlSetData(-1, "Nebraska")
GUICtrlSetData(-1, "Nevada")
GUICtrlSetData(-1, "New Hampshire")
GUICtrlSetData(-1, "New Jersey")
GUICtrlSetData(-1, "New Mexico")
GUICtrlSetData(-1, "New York")
GUICtrlSetData(-1, "North Carolina")
GUICtrlSetData(-1, "North Dakota")
GUICtrlSetData(-1, "Ohio")
GUICtrlSetData(-1, "Oklahoma")
GUICtrlSetData(-1, "Oregon")
GUICtrlSetData(-1, "Pennsylvania")
GUICtrlSetData(-1, "Rhode Island")
GUICtrlSetData(-1, "South Carolina")
GUICtrlSetData(-1, "South Dakota")
GUICtrlSetData(-1, "Tennessee")
GUICtrlSetData(-1, "Texas")
GUICtrlSetData(-1, "Utah")
GUICtrlSetData(-1, "Vermont")
GUICtrlSetData(-1, "Virginia")
GUICtrlSetData(-1, "Washington")
GUICtrlSetData(-1, "West Virginia")
GUICtrlSetData(-1, "Wisconsin")
GUICtrlSetData(-1, "Wyoming")
GUICtrlRead($Combo_1)
$Combo_2 = GUICtrlCreateCombo("Choose Your Zip Code", 30, 81, 240, 21, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
$item = $Combo_1
If $item = "Choose Your State" Then
   GUICtrlSetData(-1, "Choose Your Zip Code")
ElseIf $item = "Alabama" Then
   GUICtrlSetData(-1, "11111")
   GUICtrlSetData(-1, "22222")
Else
   If $item = "Alaska" Then
      GUICtrlSetData(-1, "33333")
      GUICtrlSetData(-1, "44444")
   EndIf
EndIf
$Button_3 = GUICtrlCreateButton("OK", 80, 140, 130, 40)
GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case Else
         If $msg = $Button_3 Then Exit
   EndSelect
WEnd
Exit

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Here, take a look at this:

#include <GuiConstants.au3>
Local $ZipCodes[51]
Local $States = 'Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|District of Columbia|Florida|Georgia|Hawaii|Idaho|Illinois|' _
        & 'Indiana|Iowa|Kansas|Kentucky|Lousiana|Main|Maryland|Massachusetts|Michigan|Minnesota|Mississippi

|Missouri|Montana|Nebraska|Nevada|' _
        & 'New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina' _
        & 'South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|WashingTon|West Virginia|Wisconsin|Wyoming'
$ZipCodes[1] = '11111|22222|'
$ZipCodes[2] = '33333|44444|'
Local $StatesArray = StringSplit($States, '|'), $Combo[3]

$MainGUI = GUICreate('State And Zip', 300, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$Combo[1] = GUICtrlCreateCombo('Choose Your State', 30, 30, 240, 21, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
$Combo[2] = GUICtrlCreateCombo('Choose Your Zip Code', 30, 81, 240, 21, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
GUICtrlSetData($Combo[1], $States)
$Button_3 = GUICtrlCreateButton('OK', 80, 140, 130, 40)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_3
            Exit
        Case $msg = $Combo[1]
            For $x = 1 To UBound($StatesArray) - 1
                If StringInStr(GUICtrlRead($Combo[1]), $StatesArray[$x]) Then
                    GUICtrlSetData($Combo[2], '')
                    GUICtrlSetData($Combo[2], 'Choose Your Zip Code|' & $ZipCodes[$x], 'Choose Your Zip Code')
                EndIf
            Next
    EndSelect
WEnd
Might get you started...

Edit: Just noticed that my copy and paste must have screwed up, it was missing 2 states and something looked wrong (Was missing Arkansas and Indiana).

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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