- 摘抄自http://www.iteye.com/topic/245624
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical" backgroundColor="black">
- <mx:Style>
- global{
- font-size:12;
- }
- </mx:Style>
- <mx:Script>
- <![CDATA[
- import com.myevent.UserEvent;
- import mx.managers.PopUpManager;
- import com.component.EditWindow;
- import com.component.User;
- import mx.controls.Alert;
- import mx.collections.ArrayCollection;
- [Bindable]
- private var ac:ArrayCollection=new ArrayCollection([{id:0,name:'张三',selected:true},{id:1,name:'李四',selected:false},{id:2,name:'王五',selected:false}]);
- private function deleteHanlder():void{
- for(var i:int=0;i<ac.length;i++){
- if(i<0) break;
- if(ac.getItemAt(i).selected){
- ac.removeItemAt(i);
- ac.refresh();
- i--;
- }
- }
- }
- public function clickHanlder(obj:Object):void{
- if(obj.chxBox.selected){
- ac.getItemAt(userDg.selectedIndex).selected=true;
- }else{
- ac.getItemAt(userDg.selectedIndex).selected=false;
- }
- }
- public function editHanlder():void{
- var ew:EditWindow=new EditWindow();
- var user:User=new User();
- user.initUser(userDg.selectedItem.id,userDg.selectedItem.name);
- ew.user=user;
- ew.addEventListener(UserEvent.USEREDITE,userEditHandler);
- PopUpManager.addPopUp(ew,this,true);
- PopUpManager.centerPopUp(ew);
- }
- public function userEditHandler(e:UserEvent):void{
- ac.getItemAt(userDg.selectedIndex).id=e.user.id;
- ac.getItemAt(userDg.selectedIndex).name=e.user.name;
- ac.refresh();
- }
- ]]>
- </mx:Script>
- <mx:DataGrid id="userDg" dataProvider="{ac}">
- <mx:columns>
- <mx:DataGridColumn dataField="id" headerText="操作">
- <mx:itemRenderer>
- <mx:Component>
- <mx:HBox>
- <mx:CheckBox id="chxBox" selected="{data.selected}" click="outerDocument.clickHanlder(this);"/>
- </mx:HBox>
- </mx:Component>
- </mx:itemRenderer>
- </mx:DataGridColumn>
- <mx:DataGridColumn dataField="id" headerText="编号"/>
- <mx:DataGridColumn dataField="name" headerText="姓名"/>
- <mx:DataGridColumn headerText="修改">
- <mx:itemRenderer>
- <mx:Component>
- <mx:HBox>
- <mx:Button label="编辑" click="outerDocument.editHanlder();"/>
- </mx:HBox>
- </mx:Component>
- </mx:itemRenderer>
- </mx:DataGridColumn>
- </mx:columns>
- </mx:DataGrid>
- <mx:Button label="删除" click="deleteHanlder();" enabled="{ac.length>0}"/>
- </mx:Application>
DataGrid里嵌入checkBox等控件等操作
最新推荐文章于 2020-06-02 14:16:28 发布