Changing DataProvider in a Flex ComboBox Problem Fix
I have stumbled across an old fix I found for a problem I had with an mx:ComboBox ages ago and thought it worth while blogging about. Basically I found that if I bound an ArrayCollection to the dataprovider of a ComboBox and then changed the contents of the ArrayCollection, the ComboBox would not update? I tried all sorts of things i.e. itemUpdated() on the provider/collection, invalidateProperies/DisplayList on the ComboBox and so on to no avail. I originally found that setting the prompt attribute in the ComboBox caused the issue but on building a quick example application I found that with or without the prompt it still fails to update. In fact its even odder without a prompt, the selected item changes but not the content within the dropdown???
So the solution is when you change the ArrayCollection assigned as the data provider to the ComboBox then assign the collection to the list control data provider for the ComboBox using the dropdown attribute, for example:
Here is an example I have done to highlight the issue, change the data provider using the top button and notice the following:
1) First ComboBox the selected item changes but the rest of the list does not (can be sporadic in it’s occurrence)? 2) Second ComboBox the list does not change at all? 3) The third ComboBox should now be fixed.
* Note * The faulty ComboBoxes will work if you have a selected item first!