tags:

views:

231

answers:

1

Suppose I have one combo box and I am switching its data provider from oldDataProvider to newDataProvider with ActionScript. Both data providers are ArrayCollections. Then, when a change occurs in the oldDataProvider ArrayCollection, it affects the combo box, although it is not its data provider anymore. Specifically, when removing an item from oldDataProvider (in the range of the newDataProvider values), it decreases the selectedIndex value of the combo box by one, changing the selected item.

Is it a good practice to switch data providers like that? I suspect this is the root of the problem. Or is it better to have only one data provider and adjust its values accordingly?

+2  A: 

Actually it's a bug of ComboBox component and it still exists in Flex 3. You should file it to Adobe bug tracking database. Here is an extended ComboBox class which should solve the problem:

package test
{
import mx.controls.ComboBox;
import mx.events.CollectionEvent;

public class FixedComboBox extends ComboBox
{
    public function FixedComboBox()
    {
     super();
    }

    override public function set dataProvider(value:Object):void
    {
     if (collection)
      collection.removeEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
     super.dataProvider = value;
    }

}
}
Hrundik
Now it works as it should, thanks a lot. I reported it as bug as well.
atas