Help adding datagridview row

I am trying to read a text file (csv) and add each row to a datagridview control, i have this code

PrivateSub btnImportContact_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnImportContact.Click

MessageBox.Show("File should be CSV with no quotes in following format: name,emailaddress,faxnumber,sendemail,sendfax")

ofd1.ShowDialog()
Dim fnameAsString = ofd1.FileName
Dim srAs System.IO.StreamReader = System.IO.File.OpenText(fname)
DoUntil sr.Peek = -1
Dim lineAsString = sr.ReadLine()
Dim arrItems()AsString = Split(line,",")
Dim dgrowAsNew DataGridViewRow
Dim dgcell(5)As DataGridViewCell
Dim aAsInteger
Dim bAsInteger = arrItems.Length
For a = 0To b
dgcell(a).Value = arrItems(a)
dgrow.Cells.Add(dgcell(a))
Next
dgAddContacts.Rows.Add(dgrow)
Loop
EndSub

My text file is as follows

test1,test@bentest.com,01422556665,1,1
test2,blah@somewhere.com,01152212211,1,1
testing3,sdfsadf@dfdf.com,445652254,1,1
test4,test@benddtest.com,01dd422556665,1,1
test5,ssdasd@sds.com,87897979,1,1

The code throws an exception "object not set to instance of an object" on the line

dgcell(a).Value = arrItems(a)

However I wont let me dim the dgcell using new keyword "arrays cannot be declared with new", even taking the array out it says "new cannot be used on a class that mustinherit"

Can anyone help? Thanks.

[3791 byte] By [MondeoST24] at [2007-12-16]
# 1
Hi,
I guess the best method on adding rows in a datagridview is to create a datatable, set it as its datasource and additems in the datatable. Here's a pseudo-code:
Dim dt As New DataTable

dt.Columns.Add(<Add column parameters>)
dgridView.DataSource = dt
' Add new row
Dim dr as DataRow = dt.NewRow()
dr("Col1") = "myValue"
dt.Rows.Add(dr)


cheers,
Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...