4 Replies Latest reply on Jun 14, 2007 12:52 PM by 187_2007

    selecting from a combobox

    187_2007 Level 1
      I have a combobox that is being populated by an Array of structures.

      <mx:ComboBox width="320" id="Vertical2_ID" dataProvider="{myVertArrayofStructs}" labelField="VERTICALS"/>

      I want to be able to selected something in that box programaticaly. Sorta like

      Vertical2_ID.SelectedIndax = "Automotive"

      But this will not work. Why is that?
        • 1. Re: selecting from a combobox
          ntsiii Level 3
          ComboBox does not provide for automatic lookups.

          You will need to loop over the dataProvider using for, matching the value of the desired property against the value you want. When you find a match, use that index to set the selectedIndex of the comboBox.

          Tracy
          • 2. Re: selecting from a combobox
            pcolby78
            If myVertArrayofStructs is an associative array, and the string "Automotive" is an object key, then you should be able to do something like:

            Vertical2_ID.SelectedItem = myVertArrayofStructs["Automotive"];

            Otherwise, as tracy said, you'll need to loop though the array the find the one you want, such as:

            for each (var item:Object in myVertArrayofStructs) {
            if (item.hasOwnProperty("someProperty") && item.someProperty == "Automotive")
            Vertical2_ID.selectedItem = item;
            }

            Hope that helps.

            Paul C.
            • 3. Re: selecting from a combobox
              187_2007 Level 1
              Well,, looks like Tracy is right. I'll post my code once finished. Thanks again.
              • 4. Re: selecting from a combobox
                187_2007 Level 1
                private function mySelectedVertResult(event:ResultEvent):void{
                var result_Array:Array = event.result as Array;
                if (result_Array.length != 0){
                for (var i:int = 0; i<result_Array.length; i++){
                for (var j:int = 1; j<myVertArrayofStructs.length; j++){
                if (result_Array .VERTICALS == myVertArrayofStructs.getItemAt(j).VERTICALS ){
                this["Vertical" + i + "_ID"].selectedIndex = j;
                }
                }
                }
                }
                }