Flex ItemRenderer as CheckBox

I have an itemRenderer as CheckBox in a Flex DataGrid.

Now, I want to make sure that only one checkbox is selected at a time. If user select's a checkbox, and then tries to select another checkbox, previous selection should be cancelled out.

How to do in Flex ?

EDIT :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">



    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.CheckBox;
            import mx.controls.RadioButton;
            import mx.controls.RadioButtonGroup;

            [Bindable]
            protected var renderer:ClassFactory;

            protected function initRenderer() {
                var group:RadioButtonGroup = new RadioButtonGroup();
                var renderer = new ClassFactory(RadioButton);
                renderer.properties = {group:group};
            }

            private var arrayC:ArrayCollection = new ArrayCollection
                (
                    [
                        {fname:"Person1",isSelected:false},
                        {fname:"Person2",isSelected:false},
                        {fname:"Person3",isSelected:false}
                    ]
                );

                    // To be called when we uncheck checkbox ..
            private function unSelect(event:MouseEvent):void {

            }
        ]]>
    </mx:Script>
    <mx:DataGrid id="dg" x="400" y="400" dataProvider="{arrayC}">
        <mx:columns>
            <mx:DataGridColumn id="dgc1" itemRenderer="{renderer}"/>
            <mx:DataGridColumn id="dgc2" dataField="fname"/>
        </mx:columns>
    </mx:DataGrid>
</mx:Application>

Answers


Try something like this:

[Bindable]
protected var renderer:ClassFactory;

protected function initRenderer() {
   var group:RadioButtonGroup = new RadioButtonGroup();
   var renderer = new ClassFactory(RadioButton);
   renderer.properties = {group:group};
}

Bind your column's itemRenderer property to renderer.

EDIT: There was originally another answer on this post that explained that it is not really a good idea to use a check box when the functionality needed is what useres will expect from Radio Buttons. Users expect when they see check boxes that they can check more than one. http://www.useit.com/alertbox/20040927.html


Need Your Help

vision.VideoPlayer embedding in GUIDE created GUI

matlab user-interface image-processing matlab-guide matlab-cvst

I'm trying to use the vision.VideoPlayer in a custom created GUIDE GUI. The video source is a camera. Right now I can get it to work with the camera but the vision.VideoPlayer object pops out of my...

sending large JSON data from android to php server can I compress?

json gzip getjson decompress data-compression

i am sending large datasets in JSON format from my android device to my server (using PHP). I want to keep bandwidth costs down. I am wondering: