I have a ComboBox where the user can select a category of products to display. The ComboBox sits on a custom component and the ArrayCollection that populates it created in the same component that displays the list.

I have two versions of the component containing the ComboBox.

Version 1:

// Create new variable tuped as
ArrayCollection

[Bindable]

privatevar
categoryList:ArrayCollection;

// initData method invoked on
creationComplete

privatefunction initData():void{

// put values
in ArrayCollection

categoryList
= new
ArrayCollection([

"All
Categories"

,"Appetizers"

,"Butcher
Shop"

,"Candy
& Chocolate"

,"Desserts"

,"Fruit
& Jams"

,"Gifts"

,"Grilling
& Barbeque"

,"Honey
& Syrup"

,"Kitchen
Accessories"

,"Little
Darlins Childrens Fun Food"

,"Oive
& Other Oils"

,"Oives
& Olive Products"

,"Pasta"

,"Pate
& Fish"

,"Rice
& Grains"

,"Sauces"

,"Seasonings
And Condiments"

,"Spreads"

,"Truffles
& Mushrooms"

,"Vegetables"

,"Vinegars"

]);

// make this
collection the data provider for catCombo

catCombo.dataProvider
= categoryList;

}

Version 2 (result of a call to a ColdFusion cfc):

// Create new variable tuped as
ArrayCollection

[Bindable]

privatevar
categoryList:ArrayCollection;

privatefunction
categoryListHandler(event:ResultEvent):void{

categoryList = event.result as
ArrayCollection;

var catObj:Object =
new Object();

catObj.merchantCategory = "All
Categories";

categoryList.addItemAt(catObj, 0);

catCombo.dataProvider =
categoryList;

}

Everything else is identical in both versions of the custom component. The ComboBox is created like this:

<mx:ComboBox id="catCombo"
rowCount="16"

styleName="glass"

change="dispatchFilter();"

labelField="merchantCategory"

/>

In both cases, catCombo is populated correctly. But…

In version 1, when I select a different category, it all works as expected.

In version 2, when I change the category, the filter says "0 items selected" and nothing displays – even if I go back to "All Categories". It's like the filter sees nothing once there is a change in the catCombo selection.

I would, of course, prefer Version 2 because the catalog - and its categories – changes month to month.

So gurus, I would really like to start the new year with Version 2 working, so any ideas would be super appreciated. Anyone in the mood?

If I'm not wrong, what I think is happening is : the objects returned in your array collection are not defined. I mean there is nothing there to tell the

compiler to look for an object which has 'merchantCategory' as one of it's members.

And when you do categoryList.addItemAt(catObj, 0); It could be replacing some data that is already at index 0 or it could be forming a new array with the previous contents of index 0 and the new contents.

What I suggest you do is to parse the returned array collection and form a new array collection and add well defined objects to it (a custom value object would be good programming).

archemedia, here the prompt property of the ComboBox would not work: 'All categories' is not just a prompt to select something, it is one of the possible selections and affects how the catalog is filtered (or, in this case, NOT filtered). But I did not know about this prompt property, which helps with another problem I had recently and for which nobody came up with a solution.

I read up on these issues over the week-end and already have plans to create a new categories class – a value object – that will hold not just category name and ID, but also the minimum and maximum prices of items in each category, data that I will have uses for later on.

I think LaVengeance is pointing me in the right direction: the Flex debugger shows the categoryList items in filter as [object Object], which explains why the filter is not seeing anything after a change event in the ComboBox. For general information, I will report the results of whatever changes I make in the next couple of days.

archemedia and LaVengeance thank you for providing great help. I shall return,

I am still having problems getting this ComboBox to work with the ArrayCollection as a dataProvider. To review, it works when I hard code the collection as shown in 'version 1' in the original post to this thread. To simplify things, I am no longer adding the "All Categories" object at the beginning of the collection.

As can be seen in the attached debugger screen shot, the event listener is now generating a proper ArrayCollection of value objects. But the problem persists; I have done everything I can think of, but cannot get it to work.

If anyone comes up with a solution, I will be extremely grateful. Any ideas?

As you can see in the attached image of the ComboBox, this populates the CB BUT, the change event causes the filters to think 0 items are selected. This does not happen when I hard code the dataProvider, as explained in the original post; in that case, everything works as expected. So, the answer to your second question is YES.

One thing I can't understand is: why is this seemingly simple issue is such a mistery? So far, over 80 people have viewed this thread, but as you see, very few want to touch it.

Anyway, thank you for trying to help. I would appreciate it if the ideas keep coming.

I don't use a VO, or CFusion though...the thing with VO's I think is you can't do a direct selectedItem on it because it's like [object],[object] you actually have to extrapolate that info or make it .toString();

Have you traced to see what is selected when you select something in the combobox? is it [object],[object]...

I guess the cheapo way of doing it would be to just capture the combo-box selection into a variable.

Then have the filter just filter from the variable which will have data, rather than the filter directly from the combo box?

It's hard enough to de-bug with all the code enough front of you, but when you are only provided only a snippet of the code it makes it even more difficult.