Reputation: 23
Here is the code I'm using below
Dim lname As New DataGridViewColumn
lname.Name = "LastName"
lname.DataPropertyName = "LastName"
DataGridView1.Columns.Add(lname)
Dim itrow = New DataGridViewRow
itrow.CreateCells(DataGridView1)
itrow.Cells(0).Value = empcoll.Item(i).LastName <<works
itrow.Cells("LastName").Value = empcoll.Item(i).LastName <<error column name can't be found
I'm having trouble with using datagridviewrow.cells("column name")
. Can anyone enlighten or help me?
Upvotes: 2
Views: 6199
Reputation: 1426
Try this (I slightly change something to try the code if it works):
Dim lname As New DataGridViewColumn
lname.Name = "LastName"
lname.DataPropertyName = "LastName"
lname.CellTemplate = New DataGridViewTextBoxCell 'I had to add this to my code
DataGridView1.Columns.Add(lname)
Dim itrow As New DataGridViewRow
itrow = DataGridView1.Rows(DataGridView1.Rows.Add())
itrow.Cells("LastName").Value = "Give here your Value"
Upvotes: 1