Hi.

I'm trying to use RadioButtons in DataGrid to select some row. One of
data entries that populate DataGrid is already selected. Say we've got
dataProvider of entries {someData : Object, selected : Boolean}. One
of entries has selected == true others are false.
The DataGrid itself is in ViewStack. When I switch selectedChild the
DataGrid is created and populated with data.
One of columns is RadioButton (item renderer derived from
RadioButton). I override data setter and in it set selected property
for this RadioButton depending on data set.
The problem is -- RadioButtons are always DEselected after creation.
Is there any way to make one of those RadioButtons selected?

Below is simple example that demonstrates the problem.

RadioButtonItemRenderer.as:
package {
        
        import mx.controls.RadioButton;

        public class RadioButtonItemRenderer extends RadioButton {
                
                public override function set data(value : Object) : void {
                        selected = Boolean(value);
                        super.data = value;
                }
                
        }
}

RadioButtonsInDataGrid.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="vertical">
        
        <mx:ViewStack id="viewStack" width="100%" height="100%">
                <mx:Canvas>
                        <mx:Button width="100" label="go to DataGrid"
click="{viewStack.selectedIndex = 1;}" />
                </mx:Canvas>
                <mx:VBox width="100%" height="100%">
                        <mx:Button width="100" label="go back"
click="{viewStack.selectedIndex = 0;}" />
                        <mx:DataGrid dataProvider="{dataProvider}">
                                <mx:columns>
                                        <mx:Array>
                                                <mx:DataGridColumn 
headerText="radio" dataField="selected"
itemRenderer="RadioButtonItemRenderer" />
                                        </mx:Array>
                                </mx:columns>
                        </mx:DataGrid>
                </mx:VBox>
        </mx:ViewStack>
        
        <mx:Script>
                <![CDATA[
                        [Bindable]
                        private var dataProvider : Array = [{selected : true}, 
{selected :
false}, {selected : false}];
                ]]>
        </mx:Script>
</mx:Application>

Any help appreciated.

R.

Reply via email to