Drag and drop

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
DarkyKnife
Top Poster
Top Poster
Posts: 109
Joined: Thu Apr 29, 2010 4:59 pm

Drag and drop
DarkyKnife
Hello, i wanted to know how to drag and drop an item and listbox shows dropped file name(not the path, only name). Thanks.
Visit my Youtube chanel
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Re: Drag and drop
CodenStuff
Hello DarkyKnife,

First off welcome to the site cooll;

This code will allow you to drag-drop items into the listbox and show only the filename of each file. To make this code work you first need to select your "ListBox" control and change its "AllowDrop" propertie to 'True' and then add the following code.
Code: Select all
Private Sub ListBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub

    Private Sub ListBox1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim draggedFiles As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
            For Each filename As String In draggedFiles
                ListBox1.Items.Add(FileIO.FileSystem.GetFileInfo(filename).Name)
            Next
        End If
    End Sub
Hope that helps cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Re: Drag and drop
Lewis
Hello CodenStuff,
I know this code was not sumbited for me but it did help alot !! Thanks,
Lewis
Image
User avatar
DarkyKnife
Top Poster
Top Poster
Posts: 109
Joined: Thu Apr 29, 2010 4:59 pm

Re: Drag and drop
DarkyKnife
Thank you very much, this helped me.
P.S. Very nice and usefull site with friendly people :)
Visit my Youtube chanel
4 posts Page 1 of 1
Return to “Tutorial Requests”