Well, somebody is asking me for a code that will load up a (.csv) format to listview. In response to what he wanted, I decided to put it in here based on how I load a .csv file to listview. This article will be in relation to the previous post that I made. I hope this will help. Enjoy!

Private Sub LoadData()
Dim fileLookUp As New OpenFileDialog
fileLookUp.Title = "Get File"
fileLookUp.Filter = "Files (*.csv)|*.csv|All Files (*.*)|*.*"
If fileLookUp.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.txtFile.Text = fileLookUp.FileName
mFileName = System.IO.Path.GetFileName(Me.txtFile.Text)
mFolder = System.IO.Path.GetDirectoryName(Me.txtFile.Text)
End If

Dim ConnectionString, CommandText As String
Dim conn As OleDb.OleDbConnection
Dim Command As OleDbCommand
Dim myString As String = txtFile.Text
Dim myIndex As Integer = myString.LastIndexOf("\") + 1
myString = myString.Substring(myIndex, myString.Length - myIndex)

Try

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mFolder & "\;Extended Properties='text;HDR=Yes'"

CommandText = "select * from " & myString & ""

conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
Command = New System.Data.OleDb.OleDbCommand(CommandText, conn)

conn.Open()

Dim t As New DataTable
' initializing its column to complement on how many fields I want to return in my query command
t.Columns.Add("v7#3")
t.Columns.Add("F2")
t.Columns.Add("F3")

' a method to access read-only the result set.
Dim reader As OleDbDataReader = Command.ExecuteReader()
While reader.Read()
' create new row
Dim r As DataRow = t.NewRow()
r(0) = reader("v7#3")
r(1) = reader("F2")
r(2) = reader("F3")

' add a row to a datatable
t.Rows.Add(r)
End While

' close reader
reader.Close()
' close the connection

conn.Close()

For i As Integer = 0 To t.Rows.Count - 1
Dim li As ListViewItem = ListView1.Items.Add(t.Rows(i)("v7#3").ToString())
li.SubItems.Add(t.Rows(i)("F2").ToString())
li.SubItems.Add(t.Rows(i)("F3").ToString())

Next

Catch ex As Exception
MsgBox("Invalid Format! Please try another.")
End Try
End Sub