I'm just looking at adding drag and both directions between my tree and grid, have the simple sample and am wondering if there is a general drag and drop overview article to help me get started. I would especially like to know the following:
- how to display a drop allowed/not allowed and to prevent a drop if the wrong type of object.
- how to drag a row/node away so as to delete the object. And to confirm this is what is wanted.
- any other D+D best practices.
Thanks, Dave
Hi Dave,
Drag and drop are pretty much the same for every control. So I don't think there is any documentation on these topics specific to Infragistics. You might want to check out Microsoft's docs on the drag and drop events.
codeslinger said:- how to display a drop allowed/not allowed and to prevent a drop if the wrong type of object.
Basically, you handle this inside the drag events. There are properties on the event args that determine what types of drops are allowed.
codeslinger said:- how to drag a row/node away so as to delete the object. And to confirm this is what is wanted.
Not sure what you mean by "confirm this is what is wanted", but how you remove a node from the tree depends on how the tree gets it's data. If it's bound, then you would have to remove the item from the underlying data source. If it's not bound, you can simply remove the node using the Remove method. The grid is always bound, so you have to remove the item from the underlying data source.
codeslinger said:- any other D+D best practices.
Again, this is probably best explained in Microsoft's docs. I would start by looking up the various events like DragDrop and DragOver (or is it DragMove, I always mix them up) on MSDN.
The only slightly tricky part of this in terms of the Infragistics controls is determining what's under the mouse at a particular point. You do this using UIElements. Here's a KB article that will point you in the right direction.
HOWTO:UltraWinGrid Mouse Position and Row Identification
Note that this article is using a point from the Mouse events and that Mouse events give you the coords in control coordinates. Drag events give you the coords in screen coordinates. So you have to call ScreenToClient before you pass them into the ElementFromPoint method.
Thanks Mike. I had actually never done any D&D before but I have figured out how it works now pretty much and see that you follow the basic MSFT model. I do have a basic drag and drop framework working but have a couple more questions if I could.
1. Regarding removing a node or row, I'm not concerned how to actually remove it but rather what event my drag source will get if I drag a node off to somewhere that will not accept a drop, such as somewhere on the desktop away from my app, and then drop it anyway. And is the proper way to drag for a delete?
2. Is it normal to pop a dialog on the DragDrop event to ask the user if they want to move, copy, delete the node/row as appropriate if it is not already clear from the context?
3. Is there a way to check if it was dropped with the LMB or RMB?
codeslinger said:1. Regarding removing a node or row, I'm not concerned how to actually remove it but rather what event my drag source will get if I drag a node off to somewhere that will not accept a drop, such as somewhere on the desktop away from my app, and then drop it anyway. And is the proper way to drag for a delete?
I could be wrong, and you should verify with MS's docs, but I don't think there is one. Usually, the control you drop onto is the one that gets the notification, not the one you dragged from.So if you drop somewhere that doesn't accept a drop, nothing happens.
codeslinger said:2. Is it normal to pop a dialog on the DragDrop event to ask the user if they want to move, copy, delete the node/row as appropriate if it is not already clear from the context?
Depends what you mean by "normal". But I don't necessarily see anything wrong with that. I'm sure there are some applications that do this. And Windows will show a context menu when you right-click and drop files.
codeslinger said:3. Is there a way to check if it was dropped with the LMB or RMB?
I'm not sure if you can tell this on the drop, but you can certainly tell when you start the drag, since most drag operations begin in MouseMove.
Thanks Mike, 1. Regarding drag for delete - would it be reasonable that if the DoDragDrop returns DragDropEffects=None that the user be asked if they want to delete what was dragged away and dropped somewhere not wanted? I'm thinking this is how they customize toolbars - by dragging them off the toolbar. I am new to this D&D stuff so am not sure about the overall paradigm. 3. Sorry my wording was wrong. I don't need to determine left or right on the drop but rather when calling DoDragDrop so I can set Copy vs. Move effects. The Infragistics samples always use SelectionDragStart event to call DoDragDrop so mine does too. Is there a way to check for LMB or RMB there at that point? Dave
codeslinger said: 1. Regarding drag for delete - would it be reasonable that if the DoDragDrop returns DragDropEffects=None that the user be asked if they want to delete what was dragged away and dropped somewhere not wanted? I'm thinking this is how they customize toolbars - by dragging them off the toolbar. I am new to this D&D stuff so am not sure about the overall paradigm.
Well, like I said, I'm no expert... but I don't think that will work. Toolbars probably don't even use true Drag and Drop, they probably simulate it in some way so they have more control. As far as I know, you won't get an event if you start a drag operation and drop over some other application.
codeslinger said: 3. Sorry my wording was wrong. I don't need to determine left or right on the drop but rather when calling DoDragDrop so I can set Copy vs. Move effects. The Infragistics samples always use SelectionDragStart event to call DoDragDrop so mine does too. Is there a way to check for LMB or RMB there at that point?
If the event doesn't give you the button, then what you could do is trap MouseDown and store the last button you got inside that event.
Thanks Mike. I think I may just ask the user if they want to delete if I get back "None" from DoDragDrop.