Sign in to follow this  
Followers 0
MattZ

ComboBox Populating from selection in other combobox

2 posts in this topic

I'm trying to write a script that reads values in from a file that populates a combobox. This populates correctly the next piece is to use the selection from the First Combobox and read a second file that fills in values for a second Combobox. This works on the first run through the script but if I select a different value for the first combobox it doesn't update the second combobox. Heres the relevant code. I got some of the code from http://www.autoitscript.com/forum/index.php?showtopic=106223- Thanks Melba23! Any help is appreciated.

While 1

Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
           Exit
    EndSwitch

;Read FacilityCombo selection
    $FacilityValue = GUICtrlRead($Combo_Facility)

;If it has changed AND the combo is closed - if we do not check for closure, the code actions while we scan the dropdown list
    If $FacilityValue <> $FacilityValueOld  And _GUICtrlComboBox_GetDroppedState($Combo_Facility) = False Then
;Reset the current text so prevent flicker from constant redrawing
        $FacilityValueOld = $FacilityValue
;Reads the Facility File into an Array 
        If Not _FileReadToArray($FacilityValue & ".txt",$Dept) Then
            MsgBox(4096,"Error", " Error reading " & $FacilityValue & ".txt     error:" & @error)
            Exit
        EndIf
;Should populate the Department Combobox - works on first pass but not on others.
        While $i <= $Dept[0]
            GUICtrlSetData($Combo_Department, $Dept[$i])
            $i = $i + 1
        WEnd
    EndIf
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

So after looking at it for over an hour and making a post a I figured it out. I had two mistakes:

1. I forgot to reinitialize $i

2. Added GUICtrlSetData($Combo_Department, "") before looping through the array to populate the combobox.

I hope this helps someone else.

Edited by MattZ

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