Fernando Briano
Fernando Briano

Reputation: 7757

Flex: Bind values in a List with ComboBox as Item Renderer

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 dynamically from an ArrayCollection.

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

Upvotes: 0

Views: 1305

Answers (2)

Fernando Briano
Fernando Briano

Reputation: 7757

We ended up making our own component: CheckboxList

Upvotes: 0

Caspar Harmer
Caspar Harmer

Reputation: 8117

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.

Upvotes: 2

Related Questions