Drag drop to copy between two Lists : List Drag Drop « Components « Flex






Drag drop to copy between two Lists

Drag drop to copy between two Lists
           
<?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 {
        firstList.dataProvider = new ArrayCollection([
            {label:"First", data:"1"},
            {label:"Second", data:"2"},
            {label:"Third", data:"3"},
            {label:"Fourth", data:"4"},
        ]);
        secondList.dataProvider = new ArrayCollection([]);
    }
    private function dragDropHandler(event:DragEvent):void {
        if (event.dragSource.hasFormat("items") ==false)
        {
            return;
        }
        event.preventDefault();
        event.currentTarget.hideDropFeedback(event);
        var dropTarget:List=List(event.currentTarget);
        var itemsArray:Array =event.dragSource.dataForFormat("items") as Array;
        var tempItem:Object ={label: itemsArray[0].label, data: itemsArray[0].data};
        var dropLoc:int = dropTarget.calculateDropIndex(event);
        IList(dropTarget.dataProvider).addItemAt(tempItem, dropLoc);
    }
  
    </mx:Script>
    <mx:HBox>
    <mx:List id="firstList" dragEnabled="true"/>
    <mx:List id="secondList" dropEnabled="true" dragDrop="dragDropHandler(event);"/>
    </mx:HBox>
</mx:Application>

   
    
    
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Dragging and dropping among three List componentsDragging and dropping among three List components
2.Drag-and-drop lets you move items from one List control to anotherDrag-and-drop lets you move items from one List control to another
3.List dropEnabled="true" ,dragMoveEnabled="true"List dropEnabled=
4.Drag And Drop List SampleDrag And Drop List Sample
5.Drag and Drop Within a ListDrag and Drop Within a List
6.Drag and Drop Between ListsDrag and Drop Between Lists
7.Drag-and-drop to move items from one MX List control to anotherDrag-and-drop to move items from one MX List control to another
8.Drag and drop to item in List To another ListDrag and drop to item in List To another List
9.List To List Drag and DropList To List Drag and Drop