Flex ComboBox - Refresh dataprovider

Go To StackoverFlow.com

1

I am using a combobox to list the contents of a folder.

With a button click I use that combobox.selectedItem to delete that folder. After I delete the data is still in the combobox. How do I go about refreshing that combobox?

2012-04-05 15:04
by SuperNinja
Remove it from the dataProvide - RIAstar 2012-04-05 15:06
@RIAstar Post that as a formal answer and I'll upvote it - JeffryHouser 2012-04-05 15:15
I was trying to reset the .prompt as well...do I need to think about just refreshing the entire canvas - SuperNinja 2012-04-05 15:27
@www.Flextras.com Sometimes I'm just too lazy. Thanks for the kick in the but ; - RIAstar 2012-04-05 15:45


3

ArrayLists and ArrayCollections (whichever you use as a 'dataProvider') both dispatch CollectionEvent.COLLECTION_CHANGE events to notify the List component (or CombBox in this case) that an item was added or removed.

So basically all you need to do, is removing the item from the dataProvider and the ComboBox will refresh automatically.

myComboBox.dataProvider.removeItemAt(myComboBox.selectedIndex);

(for this example code I'm assuming you're talking about a Spark ComboBox which only takes ILists as a dataProvider)

2012-04-05 15:42
by RIAstar
I am using mx:ComboBox....no choice in this matter for this application - SuperNinja 2012-04-05 15:45
Doesn't matter for the Spark or MX...solution works. Thank - SuperNinja 2012-04-05 15:49
@Bungdaddy Doesn't matter. The example should work just the same, except you won't get code hinting in FlashBuilder because mx:ComboBox' data type is Object. The difference is it's being converted to an IList behind the scenes - RIAstar 2012-04-05 15:52
is it possible to reset the prompt as well. After your above example I added myComboBox.prompt = "Select New" -- doesn't seem to fire - SuperNinja 2012-04-05 16:09
@Bungdaddy Perhaps you still have a selected item in the ComboBox, which would prevent the prompt from showing. Try setting selectedIndex = -1RIAstar 2012-04-05 16:11
Thanks a ton, that issue has been haunting in so many places on my UI. Greatly appreciated - SuperNinja 2012-04-05 16:19
Ads