Reputation: 1038
I need to know a maximum of the DataGridView.FirstDisplayedScrollingRowIndex
in the datagridview by programmatically.
Upvotes: 0
Views: 418
Reputation: 74605
I believe it would be the count of the rows minus the displayed count, possibly +1:
dgv.RowCount - dgv.DisplayedRowCount(true);
I say this because strictly speaking you can set a value that is anything up to the RowCount - 1
without causing an exception, but logically speaking anything you set that is higher than RowCount - DisplayedRowCount
produces no visible effect:
If you set FirstDisplayedScrollingRowIndex = 98
in a grid that shows 20 rows at once and contains 100 rows overall, you don't see row 98 at the top of the grid and a bunch of empty space making up most of it; you see ~row 80 at the top of the grid, 98 visible near the bottom and no blank space after the rows. In other words, you cannot "over-scroll" the grid past the end of the data - it hits the point where it shows the last data row at the bottom of the gridview scrolling area and then doesn't scroll any more
If you were simply meaning "what is the maximum I can set the FirstDisplayedScrollingRowIndex
to be without causing an exception" then that's dgv.RowCount - 1
Upvotes: 2