论坛首页 入门技术论坛

Flex DataGrid 数据上下移动

浏览 5500 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-05-14  
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:window="com.diaztorres.window.*" xmlns:log="com.log.*">
<mx:Script>
   <![CDATA[
       import mx.collections.IList;  
       import mx.collections.ArrayCollection          
       public function moveUp(event : MouseEvent) : void
       {			  	 
          var i : int = peopleList.selectedIndex;
          if (i >= 1&&peopleList.selectedItem)
          {           	
            IList(peopleList.dataProvider).addItemAt(peopleList.selectedItem,i-1);             		
            IList(peopleList.dataProvider).removeItemAt(i+1);
            peopleList.selectedIndex = i;
             		
           }
       }
	    
       public function moveDown(event : MouseEvent) : void
       {
	   var i : int = peopleList.selectedIndex;    	
	   if (i < (ArrayCollection(peopleList.dataProvider).length - 1) && peopleList.selectedItem)
	   {	   		 
	      IList(peopleList.dataProvider).addItemAt(peopleList.selectedItem,i + 2);             		
               IList(peopleList.dataProvider).removeItemAt(i);   
               peopleList.selectedIndex = i;  	   		   }        	
       }					
        ]]>
    </mx:Script>
    <mx:VBox horizontalAlign="center" x="618" y="176" height="264">   
    <mx:DataGrid id="peopleList"  x="198" y="66" width="302">
        <mx:columns>
            <mx:DataGridColumn headerText="Name" dataField="name"/>
            <mx:DataGridColumn headerText="Address" dataField="address"/> 
        </mx:columns>
    </mx:DataGrid>
    <mx:ControlBar width="298" autoLayout="true" horizontalAlign="right" height="26">
    	<mx:Button label="上移" click="moveUp(event)"/>
    	<mx:Button label="下移" click="moveDown(event)"/>
    </mx:ControlBar>    
</VBox>
</mx:Application>
   发表时间:2008-05-14  
少了</mx:VBox>。如果可以,上传文件最好了
0 请登录后投票
   发表时间:2008-05-14  
ArrayCollection是你自定义还是 :import mx.collections.ArrayCollection;
0 请登录后投票
   发表时间:2008-05-15  
是import mx.collections.ArrayCollection,
给DataGrid赋一下值就可以了
0 请登录后投票
   发表时间:2009-01-12  
         var i : int = peopleList.selectedIndex;        
       if (i < (ArrayCollection(peopleList.dataProvider).length - 1) && peopleList.selectedItem)  
       {               
          IList(peopleList.dataProvider).addItemAt(peopleList.selectedItem,i + 2);                    
               IList(peopleList.dataProvider).removeItemAt(i);     
               peopleList.selectedIndex = i;    
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics