This code snippet shows how to populate a DataGridView control from a CSV file using the StreamReader class.
// Contact.csv
John,Smith,john.smith@xyzmail.com
Suzan,Carter,suzan.carter@xyzmail.com
Tom,Baker,tom.baker@xyzmail.com
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sReader As New StreamReader("Contact.csv")
Dim Record() As String
DataGridView1.Columns.Add("FirstName", "First Name")
DataGridView1.Columns.Add("LastName", "Last Name")
DataGridView1.Columns.Add("Email", "Email")
While sReader.Peek() <> -1
Record = sReader.ReadLine().Split(",")
DataGridView1.Rows.Add(Record)
End While
End Sub
End Class
No comments:
Post a Comment