Drag Drop Issue.

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,016
Location
Cambridge, UK
Programming Experience
5-10
Drag Drop Issue. [Resolved]

Hi all, was wondering if someone could look over the folloeing code for me. All i'm trying to do is drag one listbox item and drag it into another...

listbox i'm dragging from....
VB.NET:
Private Sub DropBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DropBox.MouseDown
 
Me.DropBox.DoDragDrop(CType(Me.DropBox.SelectedItem, String), DragDropEffects.Copy)
 
 
 
End Sub

check the dataformat in the dragged item...

VB.NET:
Private Sub CurrentBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles CurrentBox.DragEnter
 
If e.Data.GetDataPresent(GetType(String)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub

drop it....

VB.NET:
Private Sub CurrentBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles CurrentBox.DragDrop
 
Me.CurrentBox.Items.Add(e.Data.GetData(GetType(String)))
End Sub

When i drag the first item it's fine. But every item i try to drag after that is the same as the first one.

Cheers.
 
Last edited:
in you mousedown replace with this
VB.NET:
Dim ix As Integer = dropbox.IndexFromPoint(e.X, e.Y)
If ix <> -1 Then Me.dropbox.DoDragDrop(CType(Me.dropbox.Items(ix), String), DragDropEffects.Copy)
all the examples on the web uses this indexfrompoint stuff...
 
Cheers for that johnH i wonder why my original code doesn't work though. There does'nt appear to be much difference in what actually happens between the two. Oh well, never mind......
 
selectedindex_changed event doesn't occur on mouse_down but later.
 
Back
Top