|
-
Sep 7th, 2003, 05:57 PM
#1
Thread Starter
Fanatic Member
Drag & Drop [RESOLVED]
Hiya,
I have a listbox that contains a list of filename. What I need to do is drag a text item from the listbox, and drop it onto a label. Then the label's Text property changes to the filename that was dragged onto it.
I can do that.
but if I drag a different filename from the listbox, and drop it onto the label. Nothing happens. But if I change listboxs index using the cursor keys, and then drag, it works.
Why does it do this? Im thinking the listbox is still in a drag state after I drop the item onto the label, and pressing a key interupts that state. Although I am probably wrong. I just don't understand what is happeneing.
This is the code that im using
VB Code:
Private Sub lstBeats_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstBeats.MouseDown
If e.Button = MouseButtons.Left Then
If Not lstBeats.SelectedItem Is Nothing Then
lstBeats.DoDragDrop(lstBeats.SelectedItem.ToString, DragDropEffects.Copy)
End If
End If
End Sub
Private Sub lblBeat_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblBeat.DragEnter
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub lblBeat_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblBeat.DragDrop
lblBeat.Text = (e.Data.GetData(DataFormats.StringFormat, False).ToString)
End Sub
Last edited by Geespot; Sep 8th, 2003 at 01:15 PM.
-
Sep 8th, 2003, 01:15 PM
#2
Thread Starter
Fanatic Member
Its resolved
using this code instead did the trick, dont ask me why this works and SelectedItem way doesn't
VB Code:
Private Sub lstBeats_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstBeats.MouseDown
If e.Button = MouseButtons.Left Then
If Not lstBeats.SelectedItem Is Nothing Then
Dim i As Integer = lstBeats.SelectedIndex
Dim s As String = lstBeats.Items(i).ToString
lstBeats.DoDragDrop(s, DragDropEffects.Copy)
End If
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|