`
kidd
  • 浏览: 179584 次
  • 性别: Icon_minigender_1
  • 来自: 河南
社区版块
存档分类
最新评论

FLEX AdvancedDataGrid 复选框

 
阅读更多

复选框代码:

package com.aliyun.moonmm.vm.controls.advanceDataGridClasses
{
    import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.AdvancedDataGrid;
	import mx.controls.CheckBox;
	import mx.controls.advancedDataGridClasses.AdvancedDataGridGroupItemRenderer;

	public class AdvancedDataGridGroupItemRendererEx extends AdvancedDataGridGroupItemRenderer
	{
		private var checkBox : CheckBox;
		
		public function AdvancedDataGridGroupItemRendererEx()
		{
			super();
		}

		override protected function createChildren():void
		{
			super.createChildren();
			checkBox=new CheckBox();
			checkBox.addEventListener(MouseEvent.CLICK,onChange);
			checkBox.x = 4;
			checkBox.y=label.y + 8;
			addChild(checkBox);
		}
		
		protected function onChange(e:MouseEvent):void 
		{
			e.stopPropagation();
			var cbx:CheckBox = e.currentTarget as CheckBox;
			var a:ArrayCollection = this.data.children as ArrayCollection;
			if(a != null){
				for(var i:int =0;i<a.length;i++)
				{
					a[i].selected = cbx.selected;
					a[i].selectedState = cbx.selected;
				}
			}
			data.selectedState = cbx.selected;
			var d:AdvancedDataGrid = this.owner as AdvancedDataGrid;
			d.invalidateList();
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			if (disclosureIcon)
			{
				disclosureIcon.x=disclosureIcon.x + 20;
			}
			if (icon)
			{
				icon.x=icon.x + 20;
				checkBox.x = icon.x - 30;
			}
			label.x=label.x + 20;
			
			checkBox.selected = data.selectedState;		
		}
	}
}

 

                [Embed(source="/../src/images/a_icon.png")]
     	public static const aIcon:Class;
     	
     	[Embed(source="/../src/images/b_icon.gif")]
     	public static const bIcon:Class;
     	
     	[Embed(source="/../src/images/c_win.gif")]
     	public static const cIcon:Class;

public static function iconFunc(item:Object):Class
        {
        	if(item.hasOwnProperty("id")){
        		return Constant.aIcon;
        	}
        	else{
        		switch(item.imageType){
        			case 1:return Constant.aIcon;
        			case 2:return Constant.bIcon;
        			default:return Constant.cIcon;
        		}
        	}
        	return null;
        }

 

 <mx:AdvancedDataGrid rowHeight="25" id="dataGridList" height="100%" width="100%" iconFunction="iconFunc"> 


private function iconFunc(item:Object):Class
	        {
	        	return Constant.iconFunc(item);
	        }

 

 

将复选框加入 AdvancedDataGrid 中

 

var a:ClassFactory = new ClassFactory(AdvancedDataGridGroupItemRendererEx);
	        		dataGridList.groupItemRenderer = a;

 

  • 描述: 效果
  • 大小: 20 KB
分享到:
评论
1 楼 shma1664 2012-11-15  
可以把完整的代码贴出来吗???谢谢啊!!!!

相关推荐

Global site tag (gtag.js) - Google Analytics