2 Replies Latest reply on Jan 28, 2010 9:02 AM by minetgate

    Select a value on the combobox from httpservice response.

    minetgate

      hi, I'm a new flex user, I have a problem when i try to set a selected value on the combobox from httpservice response,

       

      This is my Idea:

       

      for HTML example with PHP:

       

       

      <select name="cbx">

          <option value="1">Model 1</option>

          <option value="2">Model 2</option>

          <option value="3" selected>Model 3</option>

          <option value="4">Model 4</option>

      </select>

       

      I have selected the 3rd option right?

       

      Flex example

       

      <mx:ComboBox x="327" y="26" width="148" fontFamily="Verdana" fontSize="9" fontWeight="bold" id="cbxFormaPago" change="selectPaymentType(); ">
            <mx:ArrayCollection>
                <mx:Object data="1" label="Model 1"></mx:Object>
                <mx:Object data="2" label="Model 2"></mx:Object>
                <mx:Object data="3" label="Model 3"></mx:Object>

                <mx:Object data="4" label="Model 4"></mx:Object>
                </mx:ArrayCollection>
            </mx:ComboBox>

       

      How I select the same option on Flex? in run time not using itemindex property, I want to select the exact value in data property.

       

      please help.

        • 1. Re: Select a value on the combobox from httpservice response.
          archemedia Level 4

          In the result function of your service, loop though the items. If an item has the 'selected' attribute, store the value of the value attribute in a var called selValue (in your example selValue would be 3), next:

           

          for each (var item in cbxFormaPago.dataProvider)

          {

               if (item.data == selValue)

               {

                    cbxFormaPago.selectedItem = item;

                    break;

               }

          }

           

          Dany

          1 person found this helpful
          • 2. Re: Select a value on the combobox from httpservice response.
            minetgate Level 1

            Thank you Deny

             

            I got other idea applying the routine what you gave me.

             

             

            I made this funtion

             

            private function SelectValue(cb:ComboBox, Value:int):void
                    {
                         var i:int = 0;
                         for each (var item:Object in cb.dataProvider)
                         {
                             if (item.data == Value)
                             {
                               //cb.selectedItem = item;
                               cb.selectedIndex = i;
                               break;
                             }
                             i++;
                         }   
                    }

             

             

            I solved the problem.

             

            Thank you Deny.