Flex CheckBox in Datagrid

In the followin flex Code :
Also viewable at : http://www.cse.epicenterlabs.com/checkBoxDg/checkBoxDg.html
1. Add a row in datagrid by clicking on "AddRow"
2. Click on "CheckDg" to see the values of all the checkboxes
     - it shows "checkBox57" or "checkBox64" or some similar string
3. Now, "select" the checkBox in the first row.
4. Click again on "CheckDg"
    -it show "true"

So, initially dp.getItemAt(i).ck1 returns a CheckBox
and later it returns the "selected" value of the CheckBox?
Why this difference?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" viewSourceURL="srcview/index.html">
		<mx:DataGrid x="69" y="119" id="dgFee" editable="true" dataProvider="{dp}">
			<mx:DataGridColumn headerText="Date" dataField="ck1" width="100" editable="true" 
			editorDataField="selected" rendererIsEditor="true">
					<mx:CheckBox selected="false">
			           <mx:DataGridColumn dataField="amount" headerText="Amount" editable="true">
			             	  	  <mx:TextInput restrict="0-9"/>
		<mx:CheckBox x="130" y="54" label="Checkbox" selected="true" click="Alert.show(abc.selected.toString())" id="abc"/>
		import mx.controls.CheckBox;
		import mx.collections.ArrayCollection;
		import mx.controls.Alert;
		public var dp:ArrayCollection = new ArrayCollection();
		public function addRow():void
		  var tmp:Object = new Object();
		  tmp['amount'] = 100;
		  tmp['ck1'] = new CheckBox();
		public function delRow():void
			if(dgFee.selectedIndex != -1)
		public function loop1():void
			for(var i:int=0;i<dp.length;i++)
				<mx:Button x="29" y="89" label="AddRow" click="addRow()"/>
				<mx:Button x="107" y="89" label="DelRow" click="delRow()"/>
				<mx:Button x="184" y="89" label="CheckDg" click="loop1()"/>

Open in new window

Who is Participating?
zzynxConnect With a Mentor Software engineerCommented:
You render the attribute 'ck1' of your object (of type Object) by means of a CheckBox.
You also use the renderer as the editor (rendererIsEditor="true")

That means that when you select the checkbox, behind the scenes this statement performed:

         tmp['ck1'] = true;  (overwriting the previous value which was a CheckBox)

When you unselect it, behind the scenes this statement performed:

         tmp['ck1'] = false;

So in fact, it is of no use to have this:

tmp['ck1'] = new CheckBox();

Replace it by

        tmp['ck1'] = false;
zzynxSoftware engineerCommented:
Thanx 4 axxepting
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.