I'm working on a Windows Forms application, written with C#.
I found someone's suggestion on how to create a List<>
from DataGridView
control, but I need little more help on how to extract cell values.
Here is the code given; let's say two columns in the dataGridView1
are Name
and Address
.
How to build the List<ProjList>
object?
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);
}
Try It this Way
Create a list of your class type
Make Sure that type of list belongs to type of your data in Datagridview