首页 > 编程学习 > flex在DataGrid中添加checkbox复选框,并获取选中的值

                                     flex在DataGrid中添加checkbox复选框,并获取选中的值

1、界面:注册事件,并获取子窗体的值

//选择专题区域
private  var ztqy:DBPJZTQY = null;
private function select_ztqy():void
{
   ztqy = new DBPJZTQY();
   ztqy.x = (this.stage.stageWidth-ztqy.width)/2;
   ztqy.y = (this.stage.stageHeight-ztqy.height)/2;
   ztqy.addEventListener("clickztqy",getParamztqy); //注意这里的时间名称
  PopupEffert.show(ztqy,this,true);
}
public function getParamztqy(e:Event):void
{
var s:String= ztqy.str_mc;
var ss:String= ztqy.str_dm;
}

<mx:Button click="select_ztqy()" />

2.界面:DBPJZTQY.mxml 

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="614" height="536" creationComplete="init()" title="请选择行政地区">
<mx:Script>
<![CDATA[
import triman.common.PopupEffert;
import mx.events.DataGridEvent;
import mx.controls.CheckBox;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.managers.PopUpManager;
import mx.utils.StringUtil;
import mx.controls.Alert;


public var str_xzqmc:String = "";
public var str_xzqdm:String = "";
private var arrdata:ArrayCollection = new ArrayCollection(); //保存结果
private function init():void
{
//成都 DMLXBM='14' DMBM '5101'
 wryjcService.getXZDQ('14','5101');
}
      
/**
* 得到选中的行政地区
* */
public function getSelectXZDQ():void
{  
  str_xzqdm ="";
  str_xzqmc ="";
  var i:int=0;
for each(var obj:Object in this.grid_xzdq.dataProvider){
 try{
   if( obj.checked || obj.checked==1){ //1/true  0/false  
     str_xzqdm = (str_xzqdm==""?arrdata[i]["DMBM"]:str_xzqdm+","+arrdata[i]["DMBM"]);
      str_xzqmc = (str_xzqmc==""?arrdata[i]["DMMC"]:str_xzqmc+","+arrdata[i]["DMMC"]);
   } 
 }catch(e:Error){
   Alert.show(e.message,"错误");
 }
i++;
}
}
private function datagridRowNum(oItem:Object,iCol:int):String{   

     var iIndex:int = arrdata.getItemIndex(oItem) + 1;   
     return String(iIndex);   
   }
/**
* 关闭当前界面
* */
  private function remove_window():void
  {
   PopupEffert.remove(this);
  }
  private function queding():void
  {
    this.getSelectXZDQ();
    var outgoingEvent:Event = new Event("clickXzqdm", true); //注意这里的事件名称
  dispatchEvent(outgoingEvent);
  remove_window();
  }
private function select_XZDQ(event:ResultEvent){
  arrdata = event.result as ArrayCollection;
  this.grid_xzdq.dataProvider = arrdata;
}
/**
* 请求失败返回结果
* */
   private  function fault_result(event:FaultEvent):void
{
     Alert.show("连接到服务器出现异常!"+event.message);

]]>
</mx:Script>
<mx:RemoteObject id="wryjcService" destination="wryjcService">
      <mx:method name="getXZDQ" concurrency="last"  result="select_XZDQ(event)" fault="fault_result(event)"/>
</mx:RemoteObject>
<mx:DataGrid width="100%" height="100%" id="grid_xzdq" sortableColumns="false" draggableColumns="false">
<mx:columns>
   <mx:DataGridColumn headerText=""  labelFunction="datagridRowNum" dataField="checked"  width="50" visible="false"  />
<mx:DataGridColumn headerText="选择"  width="100">
          <mx:itemRenderer>
  <mx:Component>
  <mx:HBox horizontalAlign="center">
  <mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridListData;

private function initData():void
{
}

protected function cb_change_handler(event:Event):void
{
data.checked = !data.checked; //当点击checbox时,改变checked属性状态
}
]]>
</mx:Script>
<mx:CheckBox label="" selected="{data.checked}" change="cb_change_handler(event)"/>
</mx:HBox>
 </mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="行政地区名称" dataField="DMMC"/>
<mx:DataGridColumn headerText="行政地区代码" dataField="DMBM"/>

</mx:columns>
</mx:DataGrid>
<mx:HBox width="100%" height="44" paddingLeft="220" paddingTop="3">
<mx:Button label="确 定" click="queding()"/>
<mx:Button label="取 消" click="remove_window()"/>
</mx:HBox>

</mx:TitleWindow>

Copyright © 2010-2022 ngui.cc 版权所有 |关于我们| 联系方式| 豫B2-20100000