4 Replies Latest reply on Oct 1, 2010 2:58 PM by lynyrdbj

    How to select an item in s:ComboBox


      With the mx:ComboBox setting a selected item from a data source was easy:


      <mx:ComboBox dataProvider="{siteDictionary}" value="{getService.lastResult.@idSite}"/>


      Where the dictionary is defined as something like this:


      [Bindable] public var siteDictionary:ArrayCollection = new ArrayCollection([

         {label:"Site 1", data:'1'},

         {label:"Site 2", data:'2'}]);


      And getService returns something like:


      <service idSite="2"/>



      With spark, I tried this:


      <s:ComboBox dataProvider="{siteDictionary}" selectedItem="{getService.lastResult.@idSite}"/>


      But obviously it doesn't work, because I just have the id, not the entire object.  This is such a basic task I'm amazed that I could not find any examples on how to do it.  I did find one, where a person set the selectedIndex just by looping through the dataProvider until they found the id.  I REFUSE to accept that is the only way to do this!  Seems like a step backward to me.  Anyone know the right way?

        • 1. Re: How to select an item in s:ComboBox
          lynyrdbj Level 1

          Anyone?  I'm not looking for much here, either "yes this is the only way" or "no there is a better way" will suffice.  Much appreciated!

          • 2. Re: How to select an item in s:ComboBox
            Flex harUI Adobe Employee

            If it worked for mx:ComboBox, it should work for s:ComboBox.  Neither would

            accept just the id.  It would want the entire object.


            You're showing an ArrayCollectin of objects, but using XML like syntax so I

            am confused.

            • 3. Re: How to select an item in s:ComboBox
              lynyrdbj Level 1

              The data provider of the ComboBox is an array, and the service returns XML.  With mx, I would just say "value=" and that would select the correct item in the ComboBox.  With a spark ComboBox there is no "value" property, only "selectedItem" or "selectedIndex".  I cannot use "selectedItem" because the service only returns an id, not the whole object.

              • 4. Re: How to select an item in s:ComboBox
                Flex harUI Adobe Employee

                Sorry, didn't notice you were using the value property on mx:ComboBox.


                If you're getting back XML, unless you are going to access the data often,

                you might be better off leaving it as XML and using XMLListCollection

                instead of ArrayCollection.


                Then, since you can probably guarantee that the XML query will return one

                and only one XML node try:




                If you really have to work with XML converted to objects you'll have to loop

                through and find it.  That's what mx:ComboBox did under the covers anyway.