function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
fullvaluefullvalue 

Flex Combo Box Default Value

 Does anyone have a good suggestion for setting the default value of the combo box?  I query a record and want to set the value of the combo box.  I believe it needs to be set by seletedIndex.


Thanks for the help! 
michaelforcemichaelforce
You must take a look at the dataProvider you are using for the combobox... you must find the item in the collection and either set the "selectedItem" to be that item in the collection you wish to have selected... or you can (as you said) set the "selectedIndex" to the index within the collection of the item you want selected.
fullvaluefullvalue
So I tried setting the selectedItem but it didn't work.  My understanding is that you have to use selectedIndex but clearly I don't get that back from the query only the string value.

Code:
[Bindable]private var projectStatusPick:ArrayCollection = new ArrayCollection();

apex.describeSObjects(["SFDC_Project__c"], new AsyncResponder(describeSObjects_CB, genericFault));
private function describeSObjects_CB(result:Object):void { projectStatusPick = result[0].fields['SFDC_Project_Status__c'].picklistValues as ArrayCollection; } [Bindable] private var projectStatusRec:String; apex.query("Select SFDC_Project_Status__c From SFDC_Project__c where Id ='" + projectId + "'", new AsyncResponder( function(qr:QueryResult):void { if (qr.size > 0) { projectStatusRec = qr.records[0].SFDC_Project_Status__c;} }, handleFault) );
<mx:ComboBox id="projectstatus" dataProvider="{projectStatusPick}"/>

 

fullvaluefullvalue
So in the end I did have to search for the selectedIndex.  Here is the code.

Code:
for (var i:Number=0; i<projectStatusPick.length; i++)
{
 if(projectStatusPick[i].value == projectStatusRec){
 projectstatus.selectedIndex = i;
 break;
 }
 }