1 Reply Latest reply on Jan 26, 2014 11:55 PM by xiaoyuandlg

    Lost selected item on a DropDownList



      I have constated, for a DropDownList, if we change the dataProvider, and if we affecte it the same selected value, this one isn't selected.

      The DropDownList stay with without selected item.

      Here, a test code for the example:


      <?xml version="1.0" encoding="utf-8"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"



      minWidth="955" minHeight="600">



      import mx.binding.utils.BindingUtils;

      import mx.collections.ArrayCollection;


      private var bool:Boolean = true;


      private var arrProvider2:ArrayCollection = new ArrayCollection(["Bernard", "Peter", "Quentin", "Marie"]);

      private var arrProvider1:ArrayCollection = new ArrayCollection(["Quentin", "Peter", "Sébastien", "Florine"]);



      private var item:String;


      private var arrProvider:ArrayCollection;


      protected function button1_clickHandler(event:MouseEvent):void


           if (bool) {

                 arrProvider = arrProvider2;

                item = "Peter";


           else {

                 arrProvider = arrProvider1;

                item = "Peter";


            bool = !bool;

            btn.label = "switch dataprovider to " + (bool? "arr2": "arr1");





      <s:VGroup paddingLeft="20" paddingTop="20">

            <s:DropDownList id="dd" dataProvider="{arrProvider}" selectedItem="{item}" />

            <s:Button id="btn" click="button1_clickHandler(event)" label="switch dataprovider to arr2"/>





      In this case, we use a intermediate bindable variable.

      If, I affecte directely the value to the "selectedItem" attribut of the DropDownList, that runs fine:


      dd.selectedItem = "Peter";



      Likewise, if we change the value of "item" to empty before affecteing "Peter", that runs fine too :


      item = "";

      item = "Peter";



      Or, once it's "Peter", and another "Quentin" :

      if (bool) {

            arrProvider = arrProvider2;

           item = "Peter";


      else {

            arrProvider = arrProvider1;

           item = "Quentin";



      It seems that, the blindable variable "item" don't see the value changement, so don't transmit the selection.

      Can you give me your point of view about this event?

      Why the "Peter" value don't stay selected?