tags:

views:

385

answers:

1

I am trying to dynamically bind the visibility of a checkbox control to a data field of a repeater as follows.

<mx:Repeater id="rptrQuestions" dataProvider="{QuestionsXMLList}">
    <mx:HBox>
        <mx:CheckBox id="chkQ" 
            visible="{rptrQuestions.currentItem.CheckBox.@Visible}" 
            includeInLayout="{rptrQuestions.currentItem.CheckBox.@Visible}"/>
    </mx:HBox>
</mx:Repeater>

This code does not seem to work as the checkbox always shows up.

Anyone know what the issue might be?

A: 

I've often experienced trouble using repeaters. I try to avoid using them because they seem unpredictable and they use a lot of memory because they build all containing items at once in stead of postponing it until they are displayed.

You could try to use a List with a custom ItemRenderer, something like this:

<mx:List id="lstQuestions" dataProvider="{QuestionsXMLList}"
    itemRenderer="full.path.to.CustomListItemRenderer" />

CustomListItemRenderer:

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
    <mx:CheckBox id="checkBox" label="{expo.name}"
         visible="{question.CheckBox.@Visible}"
         includeInLayout="{question.CheckBox.@Visible}" />

    <mx:Script>
        <![CDATA[

        [Bindable]
        private var question:QuestionXMLListItem;

        public override function set data(value:Object):void
        {
            question = QuestionXMLListItem(value);
        }

        public override function get data():Object
        {
            return question;
        }

        ]]>
    </mx:Script>
</HBox>

You can use CSS to give the List the same look and feel as the repeater would get.

Maurits de Boer
Could not seem to get that to work either. I am sure I was just misssing something. My solution: I went with a repeater in a repeater. The inner repeater has the checkbox contorl within it. The inner repeater is bound to the existence of the CheckBox XML node (as opposed to using a "Visible" attribute) and so will just not appear if I do not create that XML node.
Ruel Waite