In the current project I have to implement custom infinite scrolling, meaning that when the user scrolls the page down so the last row becomes at least partially visible I have to load another bulk of data from the database.
The problem is to detect whether the last row is visible or not. So far I came up with the following solution:
gridView.TopRowChanged += GridView_TopRowChanged;
private void GridView_TopRowChanged(object sender, EventArgs e)
{
var rowVisibleState = gridView.IsRowVisible(gridView.DataRowCount - 1);
if (rowVisibleState == RowVisibleState.Visible
|| rowVisibleState == RowVisibleState.Partially)
{
LoadData();
}
}
That works fine until I group data by any column.
As you can see on the picture, scrolling reached the last row, but technically the last row is still hidden behind the group header.
Is there a way to determine if scrolling reached the bottom regardless if the data grouped or not?
You can operate with the vertical scrollbar directly to make your code more stratightforward and robust:
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
var scrollBar = gridControl1.Controls.OfType<VCrkScrollBar>().FirstOrDefault();
scrollBar.Scroll += ScrollBar_Scroll;
}
private void ScrollBar_Scroll(object sender, ScrollEventArgs e) {
if (e.NewValue == ((IScrollBar)sender).ViewInfo.VisibleMaximum) {
LoadMoreData();
}
}
Additionally, you can check the e.OldValue parameter to check the previous scrollbar state and scrolling direction.