I would like to detect when the scroll bar reaches the end of a data grid view, so I can run a function when this happens.
I was exploring the Scroll
event, but without success.
Thanks.
I would like to detect when the scroll bar reaches the end of a data grid view, so I can run a function when this happens.
I was exploring the Scroll
event, but without success.
Thanks.
This should get you close... place this in your Scroll
event and it will tell you when the last row is visible:
int totalHeight = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
totalHeight += row.Height;
if (totalHeight - dataGridView1.Height < dataGridView1.VerticalScrollingOffset)
{
//Last row visible
}
Here's another way to do it...
private void dataGrid_Scroll(object sender, ScrollEventArgs scrollEventArgs)
{
if (dataGrid.DisplayedRowCount(false) +
dataGrid.FirstDisplayedScrollingRowIndex
>= dataGrid.RowCount)
{
// at bottom
}
else
{
// not at bottom
}
}