Get Drag source data format : Drag Drop « Development « Flex

Home
Flex
1.Chart
2.Components
3.Container
4.Data Model
5.Development
6.Effects
7.Event
8.Graphics
9.Grid
10.Style
Flex » Development » Drag DropScreenshots 
Get Drag source data format
Get Drag source data format
          
<?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.Setting the dragMoveEnabled property to move instead of copySetting the dragMoveEnabled property to move instead of copy
2.Dragging and dropping within a component, to allow orderingDragging and dropping within a component, to allow ordering
3.Create DragSource object and add data to itCreate DragSource object and add data to it
4.Performing a two-way drag and dropPerforming a two-way drag and drop
5.Dragging and dropping in the same controlDragging and dropping in the same control
6.The drag initiators, and drop targetThe drag initiators, and drop target
7.Press control key as drag and dropPress control key as drag and drop
8.Canvas Drag and DropCanvas Drag and Drop
9.Specifying the drag indicator by using the DragSpecifying the drag indicator by using the Drag
10.Specify a Drag ProxySpecify a Drag Proxy
11.Enable and Disable Drag OperationsEnable and Disable Drag Operations
12.Drag Drop To ComponentDrag Drop To Component
13.Set liveDragging to true to dispatch change event continuously as moving the thumbSet liveDragging to true to dispatch change event continuously as moving the thumb
14.Get drag source from DragEventGet drag source from DragEvent
15.Canvas drag enter eventCanvas drag enter event
16.Explpicitly handle the dragOver eventExplpicitly handle the dragOver event
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.