You can loop through all the DataGridViewRows in a DGV and check each Row's Displayed
property. When you find the first one's that's true, that's your first displayed row. Continue looping and checking the Row's Selected
property.
Here's some test code:
int foundRowIndex = 0;
bool foundFirstDisplayedRow = false;
foreach (DataGridViewRow row in dataGridView.Rows) {
if (row.Displayed) {
foundFirstDisplayedRow = true;
Console.WriteLine(row.Cells[0].Value);
}
if (foundFirstDisplayedRow) {
foundRowIndex++;
if (row.Selected) {
// You've got what you need here in foundRowIndex.
}
}
}
As a bonus, you can check the Displayed property of the 7th row to make sure the user didn't do anything crazy like size the DGV to stop displaying it.