How can i get the value of the next row of my DataGridView in my FOREACH
foreach (DataGridViewRow row in dataGridViewSelection.Rows)
{
if ((bool)((DataGridViewCheckBoxCell)row.Cells[3]).Value)
{
do
{
list.Add(row.Cells[1].Value.ToString());
}
while (row.Cells[2].Value == the next row.Cells[2].Value-->of the next row);
}
}
I want to obtain the value of the same cell in the next row so i can compare them. Thank you
You'll need to use a
for
loop instead offoreach
, but this is simple since DataGridViewRowCollection implements the required info:By indexing via the index, you can easily access any other row in your loop.