DataGrid drag and drop event
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp();">
<mx:Script>
import mx.events.DragEvent;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
private function initApp():void {
srcgrid.dataProvider = new ArrayCollection([
{Artist:'A', Album:'AA', Price:1.99},
{Artist:'B', Album:'BB', Price:1.99},
{Artist:'C', Album:'CC', Price:1.99}
]);
destgrid.dataProvider = new ArrayCollection([]);
}
public function dragDropHandler(event:DragEvent):void {
var dragObj:Array= event.dragSource.dataForFormat("items") as Array;
for (var i:Number = 0; i < dragObj.length; i++) {
Alert.show(dragObj[i].Artist);
}
}
</mx:Script>
<mx:HBox>
<mx:DataGrid id="srcgrid" allowMultipleSelection="true" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true">
<mx:columns>
<mx:DataGridColumn dataField="Artist" />
<mx:DataGridColumn dataField="Album" />
<mx:DataGridColumn dataField="Price" />
</mx:columns>
</mx:DataGrid>
<mx:DataGrid id="destgrid" allowMultipleSelection="true" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" dragDrop="dragDropHandler(event);">
<mx:columns>
<mx:DataGridColumn dataField="Artist" />
<mx:DataGridColumn dataField="Album" />
<mx:DataGridColumn dataField="Price" />
</mx:columns>
</mx:DataGrid>
</mx:HBox>
</mx:Application>
Related examples in the same category