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


Messages In This Thread
[VB.NET] - ListBox Drag & Drop - [TUT] - by Fragma - 08-18-2011, 09:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to hook the keyboard. [VB.NET] [TuT] Vorfin 92 60,802 09-23-2019, 11:55 AM
Last Post: Jamimartin
  VB.NET Port Scanner [TUT] Fragma 30 14,413 11-27-2012, 11:26 PM
Last Post: ƃu∀ ıʞƃu∀
  [TUT] MD5 Encrypter & Finder [VB.NET] Fragma 12 7,835 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,739 10-07-2012, 06:56 AM
Last Post: a99
  [TUT]Auto-Update System[TUT] HB Virus 3 2,422 01-07-2012, 02:21 PM
Last Post: Mastermrz

Forum Jump:


Users browsing this thread: 1 Guest(s)