我正在使用C#編寫Windows窗體應用程序。如何將DataGridView內容轉換爲自定義對象的List <>?
我發現有人建議如何從DataGridView
控件創建List<>
控件,但我需要更多幫助來了解如何提取單元格值。
這是給出的代碼;假設dataGridView1
中的兩列是Name
和Address
。
如何構建List<ProjList>
對象?
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
ProjList = new List<ProjectMasterRec>();
foreach (DataGridViewCell dc in dr.Cells)
{
// build out MyItem
// based on DataGridViewCell.OwningColumn and DataGridViewCell.Value
// how do we code this?
}
ProjList.Add(item);
}
是否要獲取所有行列數據並將其插入列表中作爲一個記錄的字符串形式? – Abdul