0 Replies Latest reply on Apr 19, 2009 11:15 PM by spugalia

    DRAG DROP ITEMS - LIST

    spugalia Level 1

      I have two list where in I used drageed and drop items from one list to another. I always wanted a MOVE operation (COPY should not be done)

      Issue: If I hold a control key and drag on e item from one list to another it do COPY but if I hold a Control key, select two items from dragsource and drag them it do MOVE. The similar behaviour I saw in Adobe livedocs. Please let me know how to fix this, as I always need a MOVE operation to be done.

       

      My code:

      <mx:List id="allCharityList" labelFunction="charityListLabelFunc" allowMultipleSelection="true" dropEnabled="true" dragEnabled="true" dragMoveEnabled="true" wordWrap="true" variableRowHeight="true" width="100%" height="100%"/>

       

          <mx:List id="selectedCharityList" labelFunction="charityListLabelFunc" allowMultipleSelection="true" dropEnabled="true" dragEnabled="true" dragMoveEnabled="true" 
                dragDrop="dragDropHandler(event);" wordWrap="true" variableRowHeight="true" width="100%" height="100%"/>
          </mx:VBox>

       

                private function dragDropHandler(event:DragEvent):void
               {   
                                
                     if (event.dragSource.hasFormat("items"))
                    {
                        // Explicitly handle the dragDrop event.           
                      event.preventDefault()
                      event.currentTarget.hideDropFeedback(event);
                      var dropTarget:List=List(event.currentTarget);               
                      var itemsArray:Array = event.dragSource.dataForFormat("items") as Array;
                      for(var i:Number=0; i < itemsArray.length; i++)
                      {
                          var tempItem:Object = itemsArray[i];
                                             
                           var dropLoc:int = dropTarget.calculateDropIndex(event);             
                 
                              droppedCharities.addItemAt(tempItem, dropLoc);   
                              var dSource:List = List(event.dragInitiator); //When source and destination is same mean you need to rearrange the items
                              if(dSource == dropTarget)
                              {
                                  IList(dropTarget.dataProvider).removeItemAt(dSource.selectedIndex); 
                              } 
                          }
                         
                    }
                   
                   
               }