Drag and Drop Question...

M

Manuel Canas

Hi there,

This is the code that I am using to drag items from a list box and drop them
into a text box.
I'm not sure, but from what I know, each item on a list box is an object.
Let say I get a bunch of names display on a list box now, how do I get the
text of each item to drop that text into a text box?

Private Sub lstResult_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lstResult.MouseDown
If e.Button = MouseButtons.Left Then

'invoke the drag and drop operation

lstResult.DoDragDrop(lstResult.SelectedItem, DragDropEffects.Move Or
DragDropEffects.Copy)

End If

End Sub

Private Sub txtPatient_DragDrop(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles txtPatient.DragDrop

txtPatient.Text = e.Data.GetData(DataFormats.Text).ToString

' If the Ctrl key was not pressed, remove the source text to effect a

' drag-and-drop move.

If (e.KeyState And CtrlMask) <> CtrlMask Then

lstResult.SelectedItem = ""

End If

End Sub

Private Sub txtPatient_DragEnter(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles txtPatient.DragEnter

' Check to be sure that the drag content is the correct type for this

' control. If not, reject the drop.

If (e.Data.GetDataPresent(DataFormats.Text)) Then

' If the Ctrl key was pressed during the drag operation then perform

' a Copy. If not, perform a Move.

If (e.KeyState And CtrlMask) = CtrlMask Then

e.Effect = DragDropEffects.Copy

Else

e.Effect = DragDropEffects.Move

End If

Else

e.Effect = DragDropEffects.None

End If

End Sub

Somebody out there that can help me out here.

Thanks very much for your inputs on this one.

Manny
 

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