views:

125

answers:

1

I have an app with 2 DataGridView's and have implemented Drag/Drop to allow the user to move data between them. Within the context of my application dragging rows between two instances of a form isn't a meaningful action. I'm not sure how to detect it in drag enter so that I can set e.Effect to DragDropEffects.None.

If I don't do so and set it to Copy the DragDrop event fails with a cryptic exception "This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server."

While I can trap this exception to prevent a crash from happening, and abort the actual drop of data in the process it's bad practice to do so, and could be confusing to the user since the drop allowed cursor would be shown but no drop would take place.

+2  A: 

Microsoft says that any control can accept data from a drag-and-drop operation in progress, and that you can designate a control as a drop zone by setting the AllowDrop property to true. I would think that, if you set AllowDrop to false on those controls that you do not wish to be a drop zone, you should get the desired behavior.

If you want to detect drag and drop between two instances of your program, you can set an ID in the dragging object (i.e. put a GUID in the tag of the control), and check it during the drag process to see if it matches the GUID of your currently running instance.

http://msdn.microsoft.com/en-us/library/ms973845.aspx

Robert Harvey
You misunderstand what I'm asking. My dragging between DGV1 and DGV2 on my form is permitted in both directions; so I need to have AllowDrop set to true. If I have 2 instances of my app running, dragging from Instance1 to Istance2 is not permitted. I'm trying to find out how to enforce this. Basically I need a DragSourceIsFromThisProcess() function.
Dan Neely
How are you checking it prior to the drop? If you wait until the drop occurs, isn't it too late?
Robert Harvey
I'm calling DoDragDrop via a dynamically loaded MouseMove event (only active when the left button is depressed); so I can set the flag then. The DragEnter event fires after the drag has begun so I don't think there's any way it could happen out of sequence.
Dan Neely
OK, that's what I thought. I'll edit in the answer.
Robert Harvey