Populate DataGridView Using Array Objects


Submitted by:Andery Smith

Date added:26 July, 2011

Category:VB.NET

This code snippet populates a datagridview control using array objects.

Tags: datagridview

Code Snippet:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

DataGridView1.Columns.Add("FirstName", "First Name")
DataGridView1.Columns.Add("LastName", "Last Name")
DataGridView1.Columns.Add("Email", "Email")

Dim Row1(2) As Object
Row1(0) = "John"
Row1(1) = "Doe"
Row1(2) = "john.doe@mailxyz.com"

Dim Row2(2) As Object
Row2(0) = "Suzan"
Row2(1) = "Smith"
Row2(2) = "suzan.smith@mailxyz.com"

Dim Row3(2) As Object
Row3(0) = "Tom"
Row3(1) = "Baker"
Row3(2) = "tom.baker@mailxyz.com"

DataGridView1.Rows.Add(Row1)
DataGridView1.Rows.Add(Row2)
DataGridView1.Rows.Add(Row3)

End Sub
 
 

Comments