1. <?xml version="1.0" encoding="utf-8"?> 
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"> 
  3.     <mx:Script> 
  4.         <![CDATA[ 
  5.             import mx.collections.ArrayCollection; 
  6.             import mx.collections.IList; 
  7.             [Bindable] 
  8.             private var arrayCollection:ArrayCollection=new ArrayCollection([ 
  9.                 {id:"1",name:"小1"}, 
  10.                 {id:"2",name:"小2"}, 
  11.                 {id:"3",name:"小3"} 
  12.             ]); 
  13.              
  14.             public function moveUp():void{                    
  15.                 var i : int = dataGrid1.selectedIndex;   
  16.                 if (i >= 1&&dataGrid1.selectedItem){                
  17.                     IList(dataGrid1.dataProvider).addItemAt(dataGrid1.selectedItem,i-1);                     
  18.                     IList(dataGrid1.dataProvider).removeItemAt(i+1);   
  19.                     dataGrid1.selectedIndex = i;   
  20.                      
  21.                 }   
  22.             }   
  23.              
  24.             public function moveDown():void{   
  25.                 var i : int = dataGrid1.selectedIndex;         
  26.                 if (i < (ArrayCollection(dataGrid1.dataProvider).length - 1) && dataGrid1.selectedItem){                
  27.                     IList(dataGrid1.dataProvider).addItemAt(dataGrid1.selectedItem,i + 2);                     
  28.                     IList(dataGrid1.dataProvider).removeItemAt(i);      
  29.                     dataGrid1.selectedIndex = i; 
  30.                 }               
  31.             }  
  32.              
  33.             private function addColumnItem():void{ 
  34.                 arrayCollection.addItem({id:"id",name:"name"}); 
  35.                 dataGrid1.selectedIndex=arrayCollection.length; 
  36.             } 
  37.              
  38.             private function delColunmItem(colunmItem:Object):void{ 
  39.                 arrayCollection.removeItemAt(arrayCollection.getItemIndex(colunmItem)); 
  40.                 dataGrid1.selectedIndex=arrayCollection.length-1; 
  41.             } 
  42.         ]]> 
  43.     </mx:Script> 
  44.     <mx:Panel width="500" height="300" title="DataGrid简单测试"> 
  45.         <mx:HBox width="100%" height="100%"> 
  46.             <mx:DataGrid width="100%" height="100%" id="dataGrid1" dataProvider="{arrayCollection}"> 
  47.                 <mx:columns> 
  48.                     <mx:DataGridColumn dataField="id" headerText="ID"/> 
  49.                     <mx:DataGridColumn dataField="name" headerText="姓名"/> 
  50.                 </mx:columns> 
  51.             </mx:DataGrid> 
  52.             <mx:VBox width="60"> 
  53.                 <mx:Spacer height="100%"/> 
  54.                 <mx:Button label="上移" id="up" click="moveUp()" enabled="{dataGrid1.selectedItem?true:false}"/> 
  55.                 <mx:Spacer height="5"/> 
  56.                 <mx:Button label="下移" id="down" click="moveDown()" enabled="{dataGrid1.selectedItem?true:false}"/> 
  57.                 <mx:Spacer height="5"/> 
  58.                 <mx:Button label="╂" click="addColumnItem()"/> 
  59.                 <mx:Spacer height="5"/> 
  60.                 <mx:Button label="━" enabled="{dataGrid1.selectedItem?true:false}" click="delColunmItem(dataGrid1.selectedItem)"/> 
  61.                 <mx:Spacer height="100%"/> 
  62.             </mx:VBox> 
  63.         </mx:HBox> 
  64.     </mx:Panel> 
  65. </mx:Application> 

移动的代码参考地址http://www.iteye.com/topic/192956