setting VerticalScrollingOffset programmatically

2019-07-23 11:54发布

I'm using a custom scroll bar and the problem I'm facing now is that when I have thousands of rows in a datagrid and scroll all the way to the bottom, dataGrid.VerticalScrollingOffset is about + 400 higher thank customScrollbar.Value. Which ends up with dataGrid now showing last few records, because it hasn't scrolled down enough.

It would be perfect if I could set dataGrid.VerticalScrollingOffset value or get the maximum vertical scrolling value of dataGrid, I couldn't find any information on nether.

Currently I'm calculating the maximum value like rowCount*rowHeight, which doesn't give exact max value, therefore it's not scrolling down all the way. Any suggestions? Thanks!

1条回答
Fickle 薄情
2楼-- · 2019-07-23 12:17

You can use [FirstDisplayedScrollingRowIndex][1]:

// To Scroll down
this.FirstDisplayedScrollingRowIndex = this.FirstDisplayedScrollingRowIndex + 1;

If you want to have per pixel increment, place the DataGridView in a Panel whose AutoScroll property is set to true.

查看更多
登录 后发表回答