It finally seems to have loop through the entire arraycollection.

Thanks a lot to vinu, jeffry, mark, tracy and everyone for their help and 
suggestions... :)

--- In [email protected], "vin.flex" <vin.f...@...> wrote:
>
> Hi there,
> 
> You can use the following code:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml";>
>    <mx:Script>
>       <![CDATA[
>          private var _selectedValue:String;
>          private var bSelectedValueSet:Boolean = false;
>          private var bDataProviderSet:Boolean = false;
> 
>          // Override committ, this may be called repeatedly 
>          override protected function commitProperties():void
>          {
>             // invoke ComboBox version 
>             super.commitProperties();
> 
>             // If value set and have dataProvider 
>             if (bSelectedValueSet && bDataProviderSet)
>             {
>                // Set flag to false so code won't be called until 
> selectedValue is set again 
>                bSelectedValueSet=false;
>                // Loop through dataProvider 
>                for (var i:int=0;i<this.dataProvider.length;i++)
>                {
>                   // Get this item's data 
>                   var item:String = this.dataProvider[i].FIELDNAME;
>    
>                   // Check if is selectedValue 
>                   if(item == _selectedValue)
>                   {
>                      // Yes, set selectedIndex 
>                      this.selectedIndex = i;
>                      break;
>                   }
>                }
>             }
>          }
> 
>          // Trap dataProvider being set 
>          override public function set dataProvider(o:Object):void
>          {
>             // invoke ComboBox version 
>             super.dataProvider = o;
> 
>             // This may get called before dataProvider is set, so make sure 
> not null and has entries 
>             if (o!=null && o.length)
>             {
>                // Got it, set flag 
>                bDataProviderSet = true;
>             } else
>                bDataProviderSet = false;
>          }
> 
>          // set for selectedValue 
>          public function set selectedValue(s:String):void
>          {
>             // Set flag 
>             bSelectedValueSet = true;
>             // Save value 
>             _selectedValue = s;
>             // Invalidate to force commit 
>             invalidateProperties();
>          }
>       ]]>
>    </mx:Script>
> 
> </mx:ComboBox>
> 
> 
> 
> create this as a reusable component and use this instead of regular 
> combobox:
> 
> 1) Make sure to replace "FIELDNAME" in the above code with the name of the 
> field in the dataprovider.
> 
> 2) Instead of selectedindex use comboboxId.selectedValue = "Value you want to 
> ser".
> 
> this will solve your problem.
> 
> 
> vin.
>


Reply via email to