<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script><!--[CDATA[import mx.collections.ArrayCollection; public var a1:ArrayCollection = new ArrayCollection ([{ Region:"Region1",Territory:"Territory1",Territory_Rep:"Territory_Rep1",Actual:11,Estimate:111}]); public var a2:ArrayCollection = new ArrayCollection ([{ Region:"Region2",Territory:"Territory2",Territory_Rep:"Territory_Rep2",Actual:22,Estimate:222}]); public var a3:ArrayCollection = new ArrayCollection ([{ Region:"Region3",Territory:"Territory3",Territory_Rep:"Territory_Rep3",Actual:33,Estimate:333}]); public var a4:ArrayCollection = new ArrayCollection ([{ Region:"Region4",Territory:"Territory4",Territory_Rep:"Territory_Rep4",Actual:44,Estimate:444}]); public var a5:ArrayCollection = new ArrayCollection ([{ Region:"Region5",Territory:"Territory5",Territory_Rep:"Territory_Rep5",Actual:55,Estimate:555}]); public var dpFlat:ArrayCollection=new ArrayCollection(a1.toArray().concat(a2.toArray().concat(a3.toArray()).concat(a4.toArray()).concat(a5.toArray()))) import mx.events.ItemClickEvent; private function Switch(event:ItemClickEvent):void {var keycode:int=event.index; switch(keycode){//上下左右case 0:grid.dataProvider=a1;break;case 1: grid.dataProvider=a2;break;case 2:grid.dataProvider=a3;break;case 3: grid.dataProvider=a4;break;case 4:grid.dataProvider=a5;break;case 5: grid.dataProvider=dpFlat;break;}}]]--></mx:Script><mx:Panel layout="absolute"title="数据合并"horizontalCenter="0" verticalCenter="0" height="220" width="500"> <mx:DataGrid id="grid" dataProvider="{a1}" right="0" bottom="0" top="0" left="0"/> <mx:ControlBar horizontalAlign="right" ><mx:Spacer width="10%"/> <mx:ToggleButtonBaritemClick="Switch(event);"bottom="2" id="ToggleButtonBar" horizontalCenter="0"><mx:dataProvider><mx:Array> <mx:String>第一</mx:String><mx:String>第二</mx:String> <mx:String>第三</mx:String><mx:String>第四</mx:String> <mx:String>第五</mx:String><mx:String>合并</mx:String> </mx:Array></mx:dataProvider></mx:ToggleButtonBar> <mx:Spacer width="10%"/></mx:ControlBar></mx:Panel> </mx:Application> 本文转自:http://bbs.airia.cn/FLEX/thread-6638-1-56.aspx