1 Reply Latest reply on Feb 27, 2008 10:16 AM by m_hartnett

    Combo Box to display selected value on return

    nrutter
      I am having some trouble trying to figure out how to poplulate my combo box with the selected value from the db. Can anyone help me with this. I can populate my combo box just fine its just coming back into the application I can't populated it with the selected value I need


      <mx:ComboBox
      id="occurenceCode"
      prompt="Select One"
      text="{caseVO.occurenceCode}"
      change="model.currentCaseVO.occurenceCode = occurenceCode.selectedItem.data"
      labelField="OccurrenceCode"
      dataProvider="{model.acOccurrences}"
      width="100%" height="19"/>
        • 1. Re: Combo Box to display selected value on return
          m_hartnett Level 3
          Here is an article that I used to create a value aware combo box:
          http://flexblog.faratasystems.com/?p=132

          There are a number of value aware combobox implementations and articles out there however I found this article very good. Also read the comments as they point out some bug fixes and enhancements.

          Here is my code. This is a custom combobox object that will extend the flex combobox and be used in place of the flex combobox.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:ComboBox xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:Script>
          <![CDATA[

          import mx.collections.ArrayCollection;
          private var candidateValue:Object;
          private var valueDirty:Boolean = false;
          private var candidateDataProvider:Object;
          private var dataProviderDirty:Boolean = false;

          private function applyValue(val:Object):void {
          if ((val != null) && (dataProvider != null)) {

          for (var i : int = 0; i < dataProvider.length; i++) {
          if ( dataProvider != null && (val == dataProvider.data || val == dataProvider .label)) {
          ; selectedIndex = i;
          ; return;
          } } }
          selectedIndex = -1;
          } public function set value(val:Object) : void {
          candidateValue = val;
          valueDirty = true;
          invalidateProperties();
          }
          override public function set dataProvider(value:Object):void {
          candidateDataProvider = value;
          dataProviderDirty = true;
          invalidateProperties();
          }

          override protected function commitProperties():void {
          super.commitProperties();

          if (dataProviderDirty) {
          super.dataProvider = candidateDataProvider;
          dataProviderDirty = false;
          }

          if (valueDirty) {
          applyValue(candidateValue);
          valueDirty = false;
          }
          }


          ]]>
          </mx:Script>
          </mx:ComboBox>

          In order to use this you must put something like the following in your container:
          xmlns:viewUtil="com.flexmed.view.util.*"
          This points to where the custom component will be located.

          Your combobox tag should now be defined as following:
          <viewUtil:ComboBox id="locationId"
          styleName="stdInput"
          dataProvider="{model.ddlObjectO.locationDDL}"
          change="validateForm(event);"
          value="{ model.activeObjectO.direction.locationId}"
          width="203"/>

          you obviously need to substitute the dataprovider, change and value property values.