Flex/AS3 easy (I hope) drag and drop question - prevent dragging to other controls - apache-flex

I searched but couldn't find my answer, I'm sure it's easy for anyone with a little experience. I have multiple datagrids on a page, each one I want sortable with drag and drop, but I don't want items drug from one control to the other. How can I prevent a user from dragging an item out of a conrol. I would prefer to have it just stop moving with the mouse, but I am prepared to just completely cancel out of the dragging if need be.
I was trying to do something like this
dragExit="dragEvent.CANCEL"
This is obviously wrong, but I can't find the correct way to do it.
Thanks in advance.
~Mike

Ok, so you have an app with multiple drag/drop datagrids, and you only want items dragged within a datagrid, and not from 1 to the other, is how I understand this.
What you need to do is create a custom dragDrop event handler for each datagrid which has the following command: event.preventDefault(). This in effect will stop a datagrid from receiving items from another .
This does not prohibit the dragging an item outside its host's borders, but it will prohibit the item being dropped into a different datagrid.
HTH.

Related

Prevent drag outside QTreeWidget

In a QTreeWidget I want to be able to reorder items using InternalMove AND receive drops from another tree in my application.
If I set dragDropMode to InternalMove I cannot drop items inside it. However, if I set it to DragDrop it lets the user drag items out of the my QTreeWidget.
Is there a way of preventing this? Is there another way around the problem?
If you are not worried about drags outside of your application, maybe setting the DragDropMode of the other QTreeWidget in your application (or anything that derives from QAbstractItemView for that matter) to:
treeWidget->setDragDropMode(QAbstractItemView::DragOnly);
is enough to get the desired behavior. This does not prevent the items of the QTreeWidget in question from being dragged, but they cannot be dropped in the other tree, while you can still drop them (and the items from the DragOnly tree) into the tree that accepts drops. Does this help? (Admittedly not the most intricate way to attack the problem but performing some local tests it seemed to work)

How can I implement drag-out-to-delete in Flex?

I have a List component from which I'd like to be able to remove items using drag & drop, but without having a specific target. If you use the mac, the behaviour I'm looking for is something like what the Dock uses; when you drag something out of the bounds of the control it should get an icon that indicates that it'll be deleted (OSX uses a cloud or something?) and then if you release it it will be removed from the list.
How can I do this?
(If I need to provide a more clear description, please comment; I'll fill in what I can)
In my experience with drag/drop in Flex, you cannot simply drag something out and handle that. There is no dragOut event (unfortunately), so that would leave you up to the task of writing dragOver and dragDrop listeners on all the containers surrounding your dragInitiator and handling the process accordingly.
It's more time consuming and can become complicated if any of these controls already have specific dragOver and dragDrop event handlers.
Hope this helps.
Having no Flex experience all I can offer is some psuedo code which resembles how I implemented a similar effect in JavaScript, but hopefully it will get you started.
Essentially what you'll want to do is during your drag event measure the current coordinates of the object you're dragging to see if they intersect the original container and when they fall outside of its bounds call the logic to update the icon in order to indicate it will be removed. Then, on the drop event, check the coordinates once more and delete the item if needed.

Flex tree droplocation indicator stuck (edit 2/4/10, almost a totaly different question)

OK I've got a little more research on this done so I'm going to totally rephrase the question:
I have two trees, I want to be able to drag items from one tree to the other. In the receiving tree I have some logic that allows or denys the drop. I am using the native cursor feedback Like this :
DragManager.showFeedback(DragManager.COPY);
DragManager.showFeedback(DragManager.NONE);
When the logic determines NONE it properly rejects the item except the drop position indicator sticks like in the screenshot.
I know now that neither dragComplete, nor dragDrop are being fired in this situation, so I have no function to put code into that would clean that up. So how can I listen for this drag rejection?
ScreenShot shows app After drop
alt text http://img687.imageshack.us/img687/2245/treeindicatorstuck.png
Thanks
~Mike
PS with my other question: how-do-i-detect-that-drag-and-drop-operation-ended We have a way of getting an event to fire so we can clean up the tree control. I'm attaching an event listener to the stage so that as the mouse is moved (maybe I'll put it on a timer)it will constantly check if dragmanager.isdragging if it's not it will fire the tree.hideDropFeedBack. This still begs the question, what event is changing the isDragging Boolean and how do I listen for it?
You need to call tree.hideDropFeedback(); or event.target.hideDropFeedback(); to remove the drop indicators.

buttons in a datagrid in flex

i am using a data grid in flex and i am generating data from a mysql server. However, my problem is with adding a button within the datagrid so each row has one.
i have set the columns itemRenderer to mx.controls.Button although with the buttons shown in the grid there is no label on them (even though one has been set) and the assigned click event does not trigger when hitting the button. anyone have any ideas or guidance on what i am doing wrong.
Thanks
Mark
Not to worry I have sorted it. anyone with a similar issue i suggest reading this
http://www.axelscript.com/2008/02/29/using-the-itemrenderer-with-a-datagrid-in-flex/
an excellent source.

Adding drag & drop to a datagrid column in flex

I have two datagrid components and I would like to drag one column from one component to the other. I have been trying several methods but I couldnt acomplish that.
Can anybody help me with this?
What you want to do is to disable a column on the first datagrid and enable it on the second. You have to listen to DRAG_START events, find what field is the target column, and hide it on the first datagrid when the drag succeeds. Then you use a symetrical approach for the second datagrid...
I guess you will have to create a custom drag proxy visual component if you want it to be visually coherent.
Good luck =)

Resources