3 Replies Latest reply on Jul 3, 2010 8:38 AM by jack182

    ComboBox prodiver affects 2nd ComboBox provider

    jack182 Level 1

      Hello,

       

      I have this problem: I have 2 ComboBox with different provider but with same list of values. Now, when I select a value from a 1st ComboBox, the value I selected will be remove from 2nd ComboBox list value.

       

      [Bindable]
                  private var _stationOrigin:ArrayCollection;
                  [Bindable]
                  private var _stationDestination:ArrayCollection;

       

      _stationOrigin = stnService.allStationNames; // this station name came from DB through remoting
      _stationDestination = stnService.allStationNames;

       

       

      <mx:FormItem label="Origin:" required="true">
                                          <mx:ComboBox id="origin" prompt="[--- SELECT ---]" dataProvider="{_stationOrigin}" close="handleCloseEvent(event);" />
                                      </mx:FormItem>

      <mx:FormItem label="Destination:" required="true">
                                          <mx:ComboBox id="destination" prompt="[--- SELECT ---]" dataProvider="{_stationDestination}" close="handleCloseEvent(event);" />
                                      </mx:FormItem>

       

       

      ...and actionscript:

       

      private function handleCloseEvent(e:DropdownEvent):void
                  {
                      if(e.target.id == "origin" && e.currentTarget.selectedItem != null)
                      {
                                           
                          if(_stationDestination.contains(origin.selectedItem.toString()))
                          {
                              var idx:int = _stationDestination.getItemIndex(origin.selectedItem.toString());
                              _stationDestination.removeItemAt(idx);
                            
                          }
                      }

      }

       

      ..Now when I do that both the origin and destination value was remove from the combobox. It's weird because I only remove it in a destination not in origin. And also the selected value from the origin dropdownbox was gone.

       

      Any ideas on how to solve this?

       

      Thanks a lot.

      cheers.