Problem with DragDrop between 2 textboxes

M

moondaddy

I created a new vb windows application and dragged 2 textboxes onto Form1.
Then I coppied the code below from MSDN article
(http://msdn.microsoft.com/library/d.../en-us/dv_vstechart/html/vbtchimpdragdrop.asp).
The code for TextBox1 executes OK, but fails to execute for TextBox2 . Can
anyone shed some light on this for me?

Thanks.

Private MouseIsDown As Boolean = False

Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
' Set a flag to show that the mouse is down.
MouseIsDown = True
End Sub

Private Sub TextBox1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseMove
If MouseIsDown Then
' Initiate dragging.
TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
End If
MouseIsDown = False
End Sub

Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
' Check the format of the data being dropped.
If (e.Data.GetDataPresent(DataFormats.Text)) Then
' Display the copy cursor.
e.Effect = DragDropEffects.Copy
Else
' Display the no-drop cursor.
e.Effect = DragDropEffects.None
End If
End Sub

Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
' Paste the text.
TextBox2.Text = e.Data.GetData(DataFormats.Text)
End Sub
 
M

moondaddy

I figured it out. I failed to set the "Allow Drop" property in the target
control. Well y'all know my level of experience in DragDrop now.
 
J

Jeff Gaines

I figured it out. I failed to set the "Allow Drop" property in the
target control. Well y'all know my level of experience in DragDrop
now.

Yes, higher then it was before, that's how we all learn :)

Anyway, you're not the only person to have done, just honest enough to
admit it!
 

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