Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Flex CheckBox in Datagrid

Posted on 2009-07-13
2
Medium Priority
?
5,527 Views
Last Modified: 2013-11-11
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:Canvas>
		<mx:DataGrid x="69" y="119" id="dgFee" editable="true" dataProvider="{dp}">
			<mx:columns>
			<mx:DataGridColumn headerText="Date" dataField="ck1" width="100" editable="true" 
			editorDataField="selected" rendererIsEditor="true">
			<mx:itemRenderer>
				<mx:Component>
					<mx:CheckBox selected="false">
					                   </mx:CheckBox>
				        </mx:Component>
			</mx:itemRenderer>
			</mx:DataGridColumn>
			           <mx:DataGridColumn dataField="amount" headerText="Amount" editable="true">
			             <mx:itemEditor>
			             <mx:Component>
			             	  	  <mx:TextInput restrict="0-9"/>
			             </mx:Component>
			             </mx:itemEditor> 	
			           </mx:DataGridColumn>
			</mx:columns>
		</mx:DataGrid>
		<mx:CheckBox x="130" y="54" label="Checkbox" selected="true" click="Alert.show(abc.selected.toString())" id="abc"/>
<mx:Script>
	<![CDATA[
		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();
		  dp.addItem(tmp);
		}
		public function delRow():void
		{
			if(dgFee.selectedIndex != -1)
			dp.removeItemAt(dgFee.selectedIndex);
		}
 
		public function loop1():void
		{
			for(var i:int=0;i<dp.length;i++)
			{
			   Alert.show(dp.getItemAt(i).ck1);
			}
		}
	]]>
</mx:Script>
				<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()"/>
 
</mx:Canvas>	
</mx:Application>

Open in new window

0
Comment
Question by:dtivmk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 24846914
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;
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24958321
Thanx 4 axxepting
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question