Flex 3.5.0; Update ComboBox display list upon dataprovider change
Asked Answered
M

4

5

I have two related ComboBoxes ( continents, and countries ). When the continents ComboBox changes I request a XML from a certain URL. When I receive that XML i change the DataProvider for the countries ComboBox, like this:

public function displayCountryArray( items:XMLList ):void
        {
            this.resellersCountryLoader.alpha = 0;
            this.resellersCountry.dataProvider = items;
            this.resellersCountry.dispatchEvent( new ListEvent( ListEvent.CHANGE ) );
        }

I dispatch the ListEvent.CHANGE because I use it to change another ComboBox so please ignore that (and the 1st line ).

So, my problem is this: I select "ASIA" from the first continents, then the combobox DATA get's updated ( I can see that because the first ITEM is an item with the label '23 countries' ). I click the combo then I can see the countries.

NOW, I select "Africa", the first item is displayed, with the ComboBox being closed, then when I click it, the countries are still the ones from Asia. Anyway, if I click an Item in the list, then the list updates correctly, and also, it has the correct info ( as I said it affects other ComboBoxes ). SO the only problem is that the display list does not get updated.

In this function I tried these approaches

  • Converting XMLList to XMLCollection and even ArrayCollection

  • Adding this.resellersCountry.invalidateDisplayList();

  • Triggering events like DATA_CHANGE and UPDATE_COMPLETE I know they don't make much sense, but I got a little desperate.

Please note that when I used 3.0.0 SDK this did not happen.

Sorry if I'm stupid, but the flex events are killing me.

Mariettamariette answered 30/3, 2010 at 14:33 Comment(0)
C
11

Setting the dataprovider of the comboBox' dropdown seems to fix this problem.

this.resellersCountry.dataProvider = items;
this.resellersCountry.dropdown.dataProvider = items;
Coloration answered 13/4, 2010 at 14:35 Comment(1)
sorry, but I already changed the GUI and cannot check your solution. I'll try it as soon as I get the chance and accept your answer. Thanks, again.Mariettamariette
G
1

this.resellersCountry.dropdown.dataProvider = items;

works (Flex SDK 3.5)

Hope this bug fixed in 4.0

Gam answered 6/5, 2010 at 15:21 Comment(0)
S
1

In addition to Christophe´s answer:

When you are using data binding in your ComboBox you need to use the BindingUtils to set the dropdown´s dataprovider:

MXML:

<mx:ComboBox id="cb_fontFamily"
        width="100%"
        dataProvider="{ model.fontFamilies }" />

Script:

private function init():void
{
    BindingUtils.bindSetter(updateFontFamilies, model, "fontFamilies");
}

private function updateFontFamilies(fontFamilies:ArrayCollection):void
{
    if (cb_fontFamily != null) cb_fontFamily.dropdown.dataProvider = fontFamilies;
}

Thanks to Christophe for pointing in the right direction.

Snooperscope answered 14/4, 2011 at 15:28 Comment(0)
R
0

Another workaround, outlined in an Adobe Community forum post, is to avoid re-assigning a different ArrayCollection object to the ComboBox, and instead re-using (and re-populating) the original one instead:

items.removeAll();
for each (var item:* in newItems)
{
    items.addItem(item);
}
Ringleader answered 5/9, 2014 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.