For a DataGridView, how do I get the values from each row?
You can use a foreach
to iterate over the DataGridViewRow
s within the DataGridView
and use the column names to retrieve the values from the Cells
:
foreach (DataGridViewRow dr in dataGridView.Rows)
{
string col1 = dr.Cells["Col1"].Value.ToString();
string col2 = dr.Cells["Col2"].Value.ToString();
string col3 = dr.Cells["Col3"].Value.ToString();
}