[flexcoders] Re: Binding checkbox item renderer with XMLList item

2010-06-03 Thread Amy
In answer to question 3, check out the comments here 
http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_4.html to 
see how to fix CheckBox so it works properly as a DropInListItemRenderer.

--- In flexcoders@yahoogroups.com, Asif Nawaz aasif...@... wrote:

 Let we have following data in xml form.
 
 employees
    employee   name Smith /name   age 25 /age   isselected true 
 /isselected   /employee
    employee   name John /name   age 28 /age   isselected true 
 /isselected   /employee
 
    employee   name Roger /name   age 30 /age   isselected false 
 /isselected   /employee
 
    employee   name Andy /name   age 20 /age   isselected false 
 /isselected   /employee
 
    employee   name Kim /name   age 18 /age   isselected false 
 /isselected   /employee
 /employees
 
 1 - How do i create XMLList from this xml at design time in action script.2- 
 Use this XMLList object as data provider of datagrid.3- How to bind 
 isselected item of xml with checkbox. 





[flexcoders] Re: Binding checkbox item renderer with XMLList item

2010-06-02 Thread md_ars


Hello Asif,

Following code can answer your first two questions however for third question 
you need to read and understand Item Renders that I have used in my code too. I 
used the source from http://techmytongue.blogspot.com/ for my Itemrender and 
modified little bit.

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute 
creationComplete=initApp() xmlns:local=*

mx:Script
![CDATA[
 [Bindable]
private var myXMLList:XMLList; 
private function initApp():void
{
myXMLList = empType.employee;
}
private function selecLabel(item:Object):String{
if (item.isselected == true)
return Y;
else return 'N'
}
]]
/mx:Script

mx:XML id=empType xmlns=
employees
   employee
name Smith /name
age 25 /age
isselected true /isselected
   /employee
   employee
   name John /name
   age 28 /age
   isselected true /isselected
   /employee
   employee
name Roger /name
age 30 /age
isselected false /isselected
   /employee
   employee
name Andy /name
age 20 /age
isselected false /isselected
   /employee
   employee
name Kim /name
age 18 /age
isselected true /isselected
   /employee
/employees

/mx:XML

mx:DataGrid id=dgGrid dataProvider={myXMLList} editable=false
mx:columns
mx:DataGridColumn id=c1 width=55 textAlign=left 
headerText=Name dataField=name /
mx:DataGridColumn id=c2 headerText=Age 
dataField=age /
mx:DataGridColumn id=c3 width=150 textAlign=left 
headerText=Selected? dataField=isselected itemRenderer=CheckBoxItemRender

/mx:DataGridColumn
/mx:columns
/mx:DataGrid

/mx:Application

Also create CheckBoxItemRender Class as given below

package
{
import mx.containers.Canvas;
import mx.controls.CheckBox;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.controls.listClasses.IDropInListItemRenderer;

public class CheckBoxItemRender extends Canvas implements 
IDropInListItemRenderer
{
private var _listData:DataGridListData;
private var _instanceCheckBox:CheckBox = new CheckBox();
private var _currentDataFieldName:String = new String();

public function CheckBoxItemRender()
{
super();
}

   override public function set data(value:Object):void {
super.data = value;
_instanceCheckBox.data=value[_listData.dataField];
if(value[_listData.dataField] ==true){
_instanceCheckBox.selected=true
}
else if(value[_listData.dataField] ==false){
_instanceCheckBox.selected=false
}   
}

public function get listData():BaseListData
{
return _listData;
}

public function set listData(value:BaseListData):void
{
_listData = DataGridListData(value); 
}

override protected function createChildren():void {
super.createChildren();
addChild(_instanceCheckBox);
}

   }
}

Let me know if helps you.

Thanks
Arshad

--- In flexcoders@yahoogroups.com, Asif Nawaz aasif...@... wrote:

 Let we have following data in xml form.
 
 employees
    employee   name Smith /name   age 25 /age   isselected true 
 /isselected   /employee
    employee   name John /name   age 28 /age   isselected true 
 /isselected   /employee
 
    employee   name Roger /name   age 30 /age   isselected false 
 /isselected   /employee
 
    employee   name Andy /name   age 20 /age   isselected false 
 /isselected   /employee
 
    employee   name Kim /name   age 18 /age   isselected false 
 /isselected   /employee
 /employees
 
 1 - How do i create XMLList from this xml at design time in action script.2- 
 Use this XMLList object as data provider of datagrid.3- How to bind 
 isselected item of xml with checkbox.