///
/// 新建类
///
class DgvTest
{
public int Id { get; set; }
public string Name { get; set; }
}
///
/// 示例方法
///
private void TestDgv()
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
var item = row.DataBoundItem as DgvTest; //将DataGridView中每一行作为一个对象
int id = item.Id; //取对象中的属性
string name = item.Name;
}
}