How can I detect when the scroll bar reaches the e

2019-07-21 03:05发布

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.

2条回答
放荡不羁爱自由
2楼-- · 2019-07-21 03:38

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
    }
}
查看更多
聊天终结者
3楼-- · 2019-07-21 03:41

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
  }
查看更多
登录 后发表回答