views:

165

answers:

2

I am using a List with an ArrayCollection as a DataProvider. The list uses ComboBox as Item Renderer

itemRenderer="mx.controls.CheckBox"

I would like to bind the values in the List.

You have a list with several comboboxes, and those values are loaded dinamically from an ArrayCollection.

The ArrayCollection contains Objects with a boolean property for which I should bind the True/False values selected in the comboboxes.

+1  A: 

Make something like this:

<?xml version="1.0" encoding="utf-8"?>

<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import spark.events.IndexChangeEvent;

        [Bindable]
        private var myAC:ArrayCollection = new ArrayCollection(["True","False"]);

        [Bindable]
        public var editorSelectedIndex:int;

        protected function changeHandler(event:IndexChangeEvent):void
        {
            data.selectedIndex = event.target.selectedIndex;// TODO Auto-generated method stub
        }

    ]]>
</fx:Script>

<s:RichText color="#2B4381" text="{data.name}"  left="0" top="0" width="190" height="100%"/>
<s:ComboBox dataProvider="{myAC}" selectedIndex="{data.selectedIndex}" change="changeHandler(event)" left="200" top="0" height="100%"/>

Basically you can write back to the "data" property with your new data. Hope this helps.

CaspNZ
I see what you mean. But the thing is: my ArrayCollection is dinamically loaded (don't know how many objects it'll bring).The Objects in it have a boolean value, to which I should bind the checked/unchecked of the boxes.
Fernando
Well, that's easy - just modify your selectedIndex code to look at your boolean and assign a value of 0 if the boolean is true or a 1 if false. The key thing here is that you can read and write to the data property. Also, I'd appreciate if you acknowledge my contribution here, as I spent a good amount of time making this answer (I built a test project to make sure I wasn't giving you a poor answer). I don't like being taken for granted. Caspar.
CaspNZ
Oh, one more thing, the myAC variable is just a reference variable - I could have used a const there. It's only being used because the combobox needs a dataprovider.
CaspNZ
Better late than never. Sorry, and thanks for taking the time to answer!
Fernando
A: 

We ended up making our own component: CheckboxList

Fernando