DataGrid To List

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
 <mx:Script>
  <![CDATA[
   import mx.events.DragEvent;
   import mx.collections.*;
   [Bindable]
   private var _Array:Array= new Array({Product:"Fuji Apple", Price:89,LowFat:"Yes",Orgainc:"No"},{Product:"Navol Orangle", Price:0.43,LowFat:"Yes",Orgainc:"No"},{Product:"Romain Lettuce", Price:1.25,LowFat:"Yes",Orgainc:"Yes"},{Product:"Spinach", Price:0.49,LowFat:"Yes",Orgainc:"No"});
   [Bindable]
   private var targetListDP:ArrayCollection = new ArrayCollection();
   
   private function doDragDrop(event:DragEvent):void{
    var dgRow:Object=new Object();
    dgRow=event.dragSource.dataForFormat("items");
    targetList.dataProvider.addItem(dgRow[0].Product);
    event.preventDefault();//这样你可以取消默认的行为。 并不是所有事件被取消; 你必须检查最后的文档. 通过取消这个事件, 你避免显示[object Object]在列表中.
   }
  ]]>
 </mx:Script>
 <mx:HBox>
  <mx:DataGrid id="myDataGrid" dataProvider="{_Array}" dragEnabled="true" dropEnabled="true"/>
  <mx:List id="targetList"
     width="200"
     dropEnabled="true"
     dataProvider="{targetListDP}"
     dragDrop="doDragDrop(event)"/>
 </mx:HBox>
  
</mx:Application>
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: