View Full Version : Accessing a Checkbox value in Datagrid ItemRenderer

06-09-2008, 11:37 PM
Hey, i've got a problem with a project i'm currently dealing with. i've been searching the livedocs, many blogs and of course google but I can't seem to find the information I need.

Background of what I need it to do....
I have an AIR application, accessing a Sqlite database.
On the click of a button, popupmanager launches a new titlewindow, within this window is a bit of a form. Also this popup accesses data from a text field in the main application window.
The form contains information that was queried using the information from the textfield, and pulls back the results.

All this is working fine...

I then have a datagrid at the bottom, containing multiple results of a second query. The query contains the name, and a few other pieces of information about a person or multiple people that were brought back from the query.

The second column of the datagrid is an itemrenderer (id="isEntered") referencing an actionscript component that has within it a hbox and a checkbox.

The fourth column has an inline itemrenderer and an underlying component which pulls information into a combobox from a sqlite query. It also has its default selection as the value pulled from the DB too.

All this is working fine...

What i'm trying to do is submit this "form" i've created but what I need to do is know which people (listed as items in datagrid) have their checkboxes checked, and which don't. And also need to pass through the value of the first field (riderID-pulled from DB, which is listed in first column) and also need to send through the selected item that has been selected in the combobox. Whether the combobox's item has changed or not. I need this relevant information so that on the click of a "submit" button at the bottom of my form I can perform a SQL query updating the relevant results data.

<mx:DataGrid dataProvider="{getRiderDetails}" id="dgRiders" width="100%">
<mx:DataGridColumn width="35" id="riderID" dataField="riderID" />

<mx:DataGridColumn id="isEntered" visible="true" dataField="riderID"
itemRenderer="components.RBRenderer" editable="false" />

<mx:DataGridColumn headerText="#" dataField="rider_number" width="35" headerStyleName="centered"/>
<mx:DataGridColumn headerText="Rider Name" dataField="full_name" width="150"/>
<mx:DataGridColumn headerText="Entrant" dataField="entrant"/>
<mx:DataGridColumn headerText="Class" dataField="default_class" textAlign="center" headerStyleName="centered" width="180" editable="false">
<mx:HBox height="45">
<mx:Spacer width="100%"/>
<mx:ComboBox dataProvider="{classComboBoxData}" labelField="class_name" initialize="initPopup()" selectedIndex="{data.default_class-1}"></mx:ComboBox>
<mx:Spacer width="100%"/>

The code for the item renderer is here....

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center">
<mx:CheckBox id="rdo" selected="true" click="clicked()"/>

I'm sorry if the information i've provided isn't quite enough, i've tried to be as concise as possible without leaving too much out. Just ask if you need anything!

I've only been working with flex for 5 days, so please advise me where I'm going wrong!

Martin Downer.

06-10-2008, 02:35 AM
Funny, I've been struggling to solve the same problem. I don't know the answer, but here is a snippet of code that tracks which items are selected by UID. What cannot figure out is HOW TO ACQUIRE THE ITEM BY UID. itemToUid() only returns 'null'.

<?xml version="1.0" encoding="utf-8"?>
<mx:TileList xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="acToggled=new ArrayCollection();">
import mx.collections.ArrayCollection;

public var acToggled:ArrayCollection;



<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.controls.listClasses.IDropInListItemRenderer" initialize="myTL=this.owner as LangTileList">
import mx.collections.ArrayCollection;
import mx.controls.listClasses.BaseListData;
import mx.controls.TileList;
import mx.controls.CheckBox;
import LangTileList;

private var _listData:BaseListData;

private var checkedItems:ArrayCollection;

public var key:String;


private var myTL:LangTileList;

public function get listData():BaseListData {
return _listData;
public function set listData(value:BaseListData):void {
myTL=_listData.owner as LangTileList;

private function onChange(e:Event):void {
var i:int=myTL.acToggled.getItemIndex(key);
if(i>=0 && !(e.target as CheckBox).selected)
else if(i==-1 && (e.target as CheckBox).selected)


override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(key) {
if(myTL.acToggled.getItemIndex(key)>=0) //check for existence of this item

<mx:CheckBox id="ckBx" label="{data.label}" change="onChange(event)"/>