For a DataGridView, how do I get the values from each row?
Posted
by David L
on Stack Overflow
See other posts from Stack Overflow
or by David L
Published on 2010-04-05T21:24:48Z
Indexed on
2010/04/05
21:33 UTC
Read the original article
Hit count: 129
I am wondering what is the best way to go iterate through all the rows in a datagridview and get the values from the cells.
Here is what I am thinking of doing, but I don't really like it because if I rearrange the columns then the code will also have to be changed.
for (int i = 0; i < dataGridView.RowCount; i++)
{
string Value0 = dataGridView1.Rows[i].Cells[0];
string Value1 = dataGridView1.Rows[i].Cells[1];
string Value2 = dataGridView1.Rows[i].Cells[2];
}
© Stack Overflow or respective owner