12/30/09

checkbox and combobox as itemrenderer inside a datagrid

let us try to have a checkbox control over the grid and combobox.
we shall create separate components for both checkbox and combobox..

 for checkbox ::
 save the file as chkcomp
















for combobox  ::
here groupListArray is arraycollection
save the file as cmbcomp 
















the actionscript file for the above mxml...
// ActionScript file

import com.adobe.serialization.json.JSON;
import com.adobe.utils.StringUtil;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.core.Application;
import mx.corent.events.DatasEvent;
import mx.managers.CursorManager;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;



private function selectthis():void{

for (var i:int=0; i < groupListArray.length; i++){
var str:String=groupListArray.getItemAt(i).name;

if(str==data.cmbstate){

singleGroup.selectedIndex=-1;
singleGroup.prompt=data.cmbstate;

}

}

}
   
private function dispatchCmbValue():void{

var _dispatchObj:DatasEvent=new DatasEvent(singleGroup.selectedItem.name, "getComboValue", false);
dispatchEvent(_dispatchObj);
}

now to use datagrid and these two components...


 

//actionscript

private function getvalue():void{
 var userList:ArrayCollection=new ArrayCollection();
var temp_Str:String="";

  userList.addItem({firstName: "abc", lastName: "XYZ", preferredFirstName:"def",chkstate:"unselected",cmbstate:"Default"});
}
setValues();
 
 }
private function setValues():void{
userGrid.dataProvider=userList;


userGrid.addEventListener("getComboValue",getComboValue, true);
userGrid.addEventListener("getCheckValue",getCheckValue,true);


}
private function getComboValue(e:DatasEvent):void{


var fn:String="";
var ln:String="";
var pfn:String="";
var cmb:String="";

fn=userGrid.selectedItem.firstName
ln=userGrid.selectedItem.lastName
pfn=userGrid.selectedItem.preferredFirstName
cmb=userGrid.selectedItem.cmbstate

var selitem:int=userGrid.selectedIndex;
userList.removeItemAt(userGrid.selectedIndex);
userList.addItemAt({firstName: fn, lastName: ln, preferredFirstName: pfn, chkstate:sch,cmbstate:e.data.toString()},selitem);
}
var sch:String="unselected";
private function getCheckValue(e:DatasEvent):void{
var fn:String="";
var ln:String="";
var pfn:String="";
var cmb:String="";
sch=e.data.toString();
fn=userGrid.selectedItem.firstName
ln=userGrid.selectedItem.lastName
pfn=userGrid.selectedItem.preferredFirstName
cmb=userGrid.selectedItem.cmbstate

var selitem:int=userGrid.selectedIndex;
userList.removeItemAt(userGrid.selectedIndex);
userList.addItemAt({firstName: fn, lastName: ln, preferredFirstName: pfn, chkstate:e.data.toString(),cmbstate:cmb},selitem);
}



No comments:

Post a Comment

Popular Posts