vb.net load records into listview

hello there,
I have a listview with two columns one fore first name and one for last name...
I have a little button that when I click on it, it loads the text file with the data..
I would like to know how can I do the same thing but dragging the text file into the listview..
LVL 1
XK8ERAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Set the "AllowDrop" property to "true." Then add something similar to the following in your form code:
Private Sub ListView1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter
    If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop, False) Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub

Private Sub ListView1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop
    If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop, False) Then
        Dim filenames() As String = DirectCast(e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop), String())

        For Each file As String In filenames
            Me.ListView1.Items.Add(file)
        Next
    End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
>>  Set the "AllowDrop" property to "true."

This applies to the ListView object.
0
XK8ERAuthor Commented:
it works.. whats does the ListView1_DragEnter  exactly do?
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

käµfm³d 👽Commented:
The DragEnter event fires when the mouse is moved over a control while the mouse button is depressed (i.e. dragging). Inside of the handler for the event (ListView1_DragEnter), we are checking that the data associated with the drag that raised the event is a file (or group of files). Once we have verified that, we change the Effect, which under the hood causes the mouse cursor to change. This change in cursor is a cue to the user that the control which the mouse is currently hovering over can accept the type of data associated with the current drag.
0
XK8ERAuthor Commented:
amazing.. thanks a lot!
0
käµfm³d 👽Commented:
NP. Glad to help  :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.