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?
 
käµfm³d 👽Connect With a Mentor 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
 
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.