Hi :wave:
How to drag and drop one or more selected files from Windows Explorer in Listbox, i mean only the filename :p
Printable View
Hi :wave:
How to drag and drop one or more selected files from Windows Explorer in Listbox, i mean only the filename :p
1) Put in your form a Listbox
2)In listbox properties change AlloDrop=True and Name=Listbox
3) Just copy&paste the code
Private Sub ListBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub ListBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox.DragDrop
Dim DropContents() As String
Dim FileName As String
Try
DropContents = e.Data.GetData(DataFormats.FileDrop, True)
FileName = DropContents(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
If FileName <> "" And IO.File.Exists(FileName) = True Then
Dim lstFiles As ListViewItem = New ListViewItem()
lstFiles.Text = (FileName)
ListBox.Items.Add(FileName)
lstFiles = Nothing
End If
End Sub
That works :bigyello:
Thanks DigitalHand