1 Reply Latest reply on Dec 8, 2006 1:25 PM by dimival

    The Deal with Comboboxes

    Ukie_239 Level 1
      I have a component that is a combo box with a list of provinces. In the calling application, when the data value of the combobox is set on load, the associated label does not update, and I don't get why. i have the following:

      My comp combo box
      <?xml version="1.0" encoding="utf-8"?>
      <mx:ComboBox xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:dataProvider>
      <mx:Object data="AB" label="Alberta" id="AB" />
      <mx:Object data="BC" label="British Columbia" id="BC" />
      <mx:Object data="MN" label="Manitoba" />
      <mx:Object data="NB" label="New Bruswick" />
      <mx:Object data="NF" label="Newfoundland and Labrador" />
      <mx:Object data="NT" label="Northwest Territories" />
      <mx:Object data="NS" label="Nova Scotia" />
      <mx:Object data="NU" label="Nunavut" />
      <mx:Object data="ON" label="Ontartio" />
      <mx:Object data="PE" label="Prince Edward Island" />
      <mx:Object data="QC" label="Quebec" />
      <mx:Object data="SA" label="Saskatchewan" />
      <mx:Object data="YU" label="Yukon" />
      </mx:dataProvider>
      </mx:ComboBox>


      This is what I have to get the combobox data value
      companyProvince_cmb.selectedItem.data = result[0]["province"];

      the combobox itself is setup like this
      <custom:comp_cmb_province id="companyProvince_cmb" labelField="label" />

      Why doesn't eh combo box lable automatiicaly update to the proper value?
        • 1. Re: The Deal with Comboboxes
          dimival Level 1
          I had the same problem, i think it has something to do with object's identity. Anyways i solved by doing this:

          Use a function which receives the item.data you wanna display, iterate the comboBox dataprovider looking for an item whose data is the same as the one you are looking for, when you find it get use that item's position in the dataprovider and set the selectedIndex property to that value.

          In a nutshell: Find the item's position in the dataProvider and use it to set the selectedIndex property