3 Replies Latest reply on Apr 3, 2008 7:29 PM by tata6688

    Drag and drop problem with "dragEnabled" and "allowMultipleSelection"

    tata6688
      I have a Datagrid on which I set "dragEnabled = false" because I manage the drag and drop by myself (using DragManager.doDrag()). I also have "allowMultipleSelection = true" because I may drag multiple items at once.

      The problem is that when dragEnabled is set to false, as soon as you start dragging multiple selected items, only the item where the mouse event occures stay selected, all other items don't stay selected.

      Steps to reproduce, on a datagrid with dragEnabled set to false and allowMultipleSelection set to true:

      1. Select 2 items using the "SHIFT" key on the keyboard and the mouse left button.
      2. Release the key and the mouse button: two items are selected.
      3. Press down the mouse button on one of the selected item and start dragging the items using "DragManager.doDrag()": only one item stay selected!

      With dragEnabled set to true, it works: both items stay selected. But the problem with setting dragEnabled to true is that sometimes it seems it prevents custom drag and drop management to work properly. DragManager.doDrag() doesn't seems to work then and the custom proxy image is not used! To trigger that bug causing the DragManager.doDrag() to not work properly, you just have to click on an item in the datagrid while moving the mouse really fast. DragManager.doDrag() is then called but doesn't seem to work!

      So I do not have a good workaround here. I can't set dragEnabled to true because of the bug and, if I set it to false, I'm unable to drag multiple items without keeping the "SHIFT" key pressed on the keyboard.

      If you have any idea on how to workaround this problem I would be really happy!

      Thank you in advance.

      tata668



        • 1. Re: Drag and drop problem with "dragEnabled" and "allowMultipleSelection"
          tata6688 Level 1
          By the way, Is it possible for a moderator to change my screen name to "tata668"? That would be really appreciated. I don't want to display my email address like this and I'm not able to change it in my profile!

          Thank you!
          • 2. Drag and drop problem with "dragEnabled" and "allowMultipleSelection"
            tata6688 Level 1
            I did find a way to workaround this issue if it can help someone.

            I was doing sometimes like this (simplified here) to trigger the dragAndDrop:

            =================

            dg.dragEnabled = true;

            dg.addEventListener(MouseEvent.MOUSE_DOWN, myMouseDownHandler);

            protected function myMouseDownHandler(event:MouseEvent):void
            {
            this.addEventListener(MouseEvent.MOUSE_MOVE, myDragStartHandler);
            }

            protected function myDragStartHandler(event:MouseEvent):void
            {
            DragManager.doDrag(...);
            }
            =================

            The fix was to add a "true" when adding the mouseMove event:

            this.addEventListener(MouseEvent.MOUSE_MOVE, myDragStartHandler, true);

            That way my custom drag and drop management always starts before the default one and that workarounds the bug mentionned in my first message.





            • 3. Re: Drag and drop problem with "dragEnabled" and "allowMultipleSelection"
              tata6688 Level 1
              Update 2, if it can help someone:

              Finally I don't manage the drag and drop by myself using DragManager.doDrag(...). Why? Because doing so if the user clicks on the scrollbars, on the datagrid header or on an empty row, it triggers the drag start and that is ugly. By letting Flex managing the drag and drop process, this doesn't append. BUT I was unable to use a custom proxy image then. Until I found this article:

              http://www.dgrigg.com/post.cfm/11/03/2006/DataGrid-Drag-Image

              The trick is:

              1) save the mouseX and mouseY using the mousedown event.
              2) override dragImage(), as the article says, to create your custom proxy, attaching to it a FlexEvent.UPDATE_COMPLETE event, saving it to a class variable and returning it.
              3) When you receive the FlexEvent.UPDATE_COMPLETE event, you update the proxy position (that is saved in a class variable) using the saved mouseX and mouseY and you remove the listener to the event:



              When you drop the proxy, you access the dragged items in : event.dragSource.dataForFormat("items")

              Hope this helps, I spent lot of time trying to resolve this issue! Now it works perfectly! :-)