2

这是我在下面使用的代码

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

我在使用datagridviewrow.cells("column name"). 任何人都可以启发或帮助我吗?

4

1 回答 1

1

试试这个(如果它有效,我会稍微改变一些东西来尝试代码):

  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"
于 2012-11-27T14:46:23.620 回答