Trouble with DragDrop event

J

Jim R

I am trying to use Dragdrop event on a control in a VB.NET 2005 app.
The app is getting the DragEnter event, but is never getting a
DragDrop event.
My control has its "AllowDrop" property set to "True". But it seems
to me that I am missing something very fundamental.
Thanks in advance for any help.
Jim
 
J

Jim R

You also have to support dragover.
I have an event handler for Dragover and the code is receiving the
event when there is a drag over. The code is also receiving the
DragEnter event. I do not understand how that effects receiving the
Dragdrop event. Why would I not recieve a DragDrop event?
 
G

Guest

Hello Jim,

I've got a similar Prob, but only with specific controls (toolstripbutton).
In general you should use the dragenter-event to verify wether the control is
a valid target for your D&D operation. To set allowdrop=true only declares
the control as a potential target for ANY d&d-op, in dragenter you'll be able
to specify wether the control accepts a specific d&d-op. You do that by
setting the e.effect to a certain dragdropeffect. Example:

Private Sub DragEnters(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs)
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub

This checks if the dragged data is a text and gives the message to the
d&d-op that the handled control is a valid target. Visual expression is the
change of mouse-cursor. If you don't set e.effect (to move, copy, or all), no
dragdrop-event will occur!

HTH

Volker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top