Drag and drop from List to DataGrid : DataGrid Drag Drop « Grid « Flex






Drag and drop from List to DataGrid

Drag and drop from List to DataGrid
       
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp();">
    <mx:Script>
    
    import mx.events.DragEvent;
    import mx.managers.DragManager;
    import mx.core.DragSource;
    import mx.collections.IList;
    import mx.collections.ArrayCollection;
    private function initApp():void {
        srcList.dataProvider = new ArrayCollection([
            {label:"First", data:"1"},
            {label:"Second", data:"2"},
            {label:"Third", data:"3"},
            {label:"Fourth", data:"4"},
        ]);
        destDG.dataProvider = new ArrayCollection([]);
    }
    private function dragDropHandler(event:DragEvent):void {
        if (event.dragSource.hasFormat("items")  == false)
        {
           return;
        }
        event.preventDefault();
        event.currentTarget.hideDropFeedback(event);
        var dropTarget:DataGrid =DataGrid(event.currentTarget);
        var itemsArray:Array =event.dragSource.dataForFormat('items') as Array;
        var tempItem:Object ={ label: itemsArray[0].label,data: itemsArray[0].data,date: new Date()};
        var dropLoc:int = dropTarget.calculateDropIndex(event);
        ArrayCollection(dropTarget.dataProvider).addItemAt(tempItem, dropLoc);
        
    }
  
    </mx:Script>
    <mx:HBox>
        <mx:List id="srcList" dragEnabled="true" dragMoveEnabled="true"/>
        <mx:DataGrid id="destDG" dropEnabled="true" dragDrop="dragDropHandler(event);">
            <mx:columns>
                <mx:DataGridColumn dataField="label"/>
                <mx:DataGridColumn dataField="data"/>
                <mx:DataGridColumn dataField="date"/>
            </mx:columns>
        </mx:DataGrid>
    </mx:HBox>
</mx:Application>

   
    
    
    
    
    
    
  








Related examples in the same category

1.DataGrid accepting dragging and dropping from another DataGridDataGrid accepting dragging and dropping from another DataGrid
2.Handle dragEnter event for DataGridHandle dragEnter event for DataGrid
3.DataGrid drag enter eventDataGrid drag enter event
4.Drag and drop between DataGridDrag and drop between DataGrid
5.Drag and move between DataGridDrag and move between DataGrid
6.Get drag initiator DataGrid from DragEventGet drag initiator DataGrid from DragEvent
7.DataGrid drag and dropDataGrid drag and drop
8.drag and move DataGrid itemsdrag and move DataGrid items
9.DataGrid drag and drop eventDataGrid drag and drop event
10.Drag an Image to DataGrid and do calculation based on new added itemDrag an Image to DataGrid and do calculation based on new added item
11.Drag and drop rows from either DataGrid control to the otherDrag and drop rows from either DataGrid control to the other
12.Move or copy data from a Spark List control to an MX DataGrid control by drag and dropMove or copy data from a Spark List control to an MX DataGrid control by drag and drop