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

Mobile device is detected as non mobile device

asp.net mobile mobile-website

I've included a mobile web form in my asp.net project, I thought that it could/should be seen just for my mobile users but I realize that it can also be seen from any browser, I don't see problem t...

ERB & PHP together. *.php.erb?

php ruby-on-rails web-applications erb

I have to work with another team that is developing in php, when I'm developinging ruby. Normally this isn't a problem, as they usually hand the source off to me to finish. There are multiple reaso...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.