Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] - ListBox Drag & Drop - [TUT]
#1
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...

[Image: dragdrlpl.gif]

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.
Thumbsup
Reply
#2
If you wanted to be fancy you could do this with sorting the parts of the filepath string out to get the file format, filename, and directory location into 3 different segments, or use a listbox with 3 columns for those items on every dragdrop
Reply
#3
Nice detailed and helpful tutorial. I hope to see more like this. Thanks for the share.

[Image: tumblr_l1q0cxbD0h1qzjz68o1_250.gif]

Reply
#4
This is nice it could be helpful for beginners, Good Job Smile
Reply
#5
Thanks for this tutorial, i will use this for something i am making.
Reply
#6
Thanks for the share this is actually very useful.
~ Digital-Punk
Reply
#7
Thanks For This Guide.
I Never Seen This Trick Anywhere Else.
Reply
#8
I've got one that will drag and drop files with multiple columns to a listview if anyone wants that, i'll post it up at some point.
Reply
#9
Cool man I would like to take a peak at that thanks again.
~ Digital-Punk
Reply
#10
I don't get what the point is of this... Sorry!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to hook the keyboard. [VB.NET] [TuT] Vorfin 92 60,969 09-23-2019, 11:55 AM
Last Post: Jamimartin
  VB.NET Port Scanner [TUT] Fragma 30 14,470 11-27-2012, 11:26 PM
Last Post: ƃu∀ ıʞƃu∀
  [TUT] MD5 Encrypter & Finder [VB.NET] Fragma 12 7,850 11-25-2012, 10:36 PM
Last Post: ƃu∀ ıʞƃu∀
  [TUT] How to make a simple WebBrowser in VB 2010! [TUT] - [ Pictures] Statics 95 61,884 10-07-2012, 06:56 AM
Last Post: a99
  [TUT]Auto-Update System[TUT] HB Virus 3 2,428 01-07-2012, 02:21 PM
Last Post: Mastermrz

Forum Jump:


Users browsing this thread: 1 Guest(s)