将datagridview数据绑定到列表

时间:2013-11-14 12:52:13

标签: vb.net datagridview

我需要用datagridview数据填充列表,

name  fathername
x     xa
y     ya

datagridview看起来像上面的列名'name'和'fathername'

现在我需要填写清单

myList = New List(Of mydata)

Public Class mydata
   Public name As String
   Public fathername As String
End Class       

任何人都可以帮忙。

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

Dim myList As List(Of mydata) = New List(Of mydata)
Dim newItem As mydata
For Each row As DataGridViewRow In DataGridView1.Rows
    newItem = New mydata()
    newItem.name = row.Cells("name").Value
    newItem.fathername = row.Cells("fathername").Value
    myList.Add(newItem)
Next