1
votes

Currently I have a function that searches through every row in my DataGridView and looks like so.

 For Each row As DataGridViewRow In DataGridView1.Rows
 Next

However due to an issue caused by something else I need to make it start the For Each Row at a specific row. I've tried "For Each row As DataGridViewRow In DataGridView1.Rows.IndexOf(RowToStartAt)" However this appears to be the wrong method to use.

Is what I'm trying to do actually possible or not? Or have I just tried to use the wrong method?

1

1 Answers

2
votes

You could use this kind of syntax

For Each row in dgv.Rows.Cast(Of DataGridViewRow)().Skip(5)
    Console.WriteLine(row.Cells(0).Value.ToString())
Next

In this example the loops skips the first 5 rows and then starts its enumeration

Not sure if this is really beneficial or not. A traditional for ... loop is probably more clearer but as Linq goes this achieve the result required.