08-18-2011, 09:12 AM
Not really a tutorial, more just a simple guide.
People love programs which are simple and easy to use, which is why the whole drag & drop feature is so big lately.
The following snippets of code will allow users to drag files from their computer, directly into your ListBox control, like so...
Firstly, under your ListBox properties, set AllowDrop to True.
Under your ListBox's DragOver event, add the following:
The above code simply determines what is happening when a file is dragged over the ListBox control.
Next up, add the following to the ListBox's DragDrop event:
This gets the data of the file(s) and adds the location as an Item into your ListBox. I've also set a restriction on it, so that only .mp3 files can be added, although this can be removed/edited to fit your needs.
Hope this helps some of you.
People love programs which are simple and easy to use, which is why the whole drag & drop feature is so big lately.
The following snippets of code will allow users to drag files from their computer, directly into your ListBox control, like so...
Firstly, under your ListBox properties, set AllowDrop to True.
Under your ListBox's DragOver event, add the following:
Code:
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
The above code simply determines what is happening when a file is dragged over the ListBox control.
Next up, add the following to the ListBox's DragDrop event:
Code:
Dim file As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop, True), System.String())
For Each s As String In file
If s.Contains(".mp3") Then
ListBox.Items.Add(s)
Else
Exit Sub
End If
Next
This gets the data of the file(s) and adds the location as an Item into your ListBox. I've also set a restriction on it, so that only .mp3 files can be added, although this can be removed/edited to fit your needs.
Hope this helps some of you.