Hi there,

I am trying to make the radio button in the first row of my datagrid
auto-selected by default through a data provider, which gains its data
though addRadioButton function.

However, it shows as selected and unselected alternatively, whenever I
click the "add RB" button. What could have I done wrong? Many thanks.



Main.mxml
========

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009";
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Script>
    <![CDATA[
        [Bindable]
        private var myDP:Array = new Array();
        private var selected:Number = -1;
        private var counter:Number = 0;

        private function addRadioButton():void {
            var isSelected:Boolean;
            if (selected == -1) {
                isSelected = true;
                selected = myDP.length;
            } else {
                isSelected = false;
            }
            myDP.push({
                isSelected: isSelected,
                no: "Radio Button No: " + (++counter)
            });
            myDG.dataProvider = myDP;
        }
    ]]>
    </fx:Script>
    <s:Panel><s:VGroup>
    <mx:DataGrid id="myDG">
        <mx:columns>
            <mx:DataGridColumn dataField="isSelected" width="100"
itemRenderer="myRadioButton"/>
            <mx:DataGridColumn dataField="no" width="200"/>
        </mx:columns>
    </mx:DataGrid>
    <mx:ControlBar>
        <s:Button id="btnAdd" label="Add RB" click="addRadioButton()"/
>
    </mx:ControlBar>
    </s:VGroup></s:Panel>
</s:Application>



myRadioButton.as
=============

package
{
    import mx.controls.*;
    public class myRadioButton extends RadioButton
    {
        public function myRadioButton()  { super(); }

        override public function set data(value:Object):void {
            super.data = value;
            if (value.isSelected == true) {
                this.selected = true;
            } else {
                this.selected = false;
            }
            invalidateDisplayList();
        }
    }
}

-- 
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en.

Reply via email to