2
votes

Let's say I have a DataGridView Control that displays about 100 records of a specified table. Every time a user scrolls down to the lowest point, I want to add another 100 records to the DataSet that stands behind my DataGridView.

I knwo that a DataGridView Control has a Scroll Event like private void DataGridView_Scroll(object sender, ScrollEventArgs e), and that the ScrollEventArgs give me the ScrollOrientation and the ScrollEventType. But how exactly do I figure out exactly when the scroll has reached the end of the scroll bar?

Tnks.

3

3 Answers

0
votes

It sounds like you might want to look at "virtual mode". The data binding works differently, but it is well suited to lazy data fetching.

0
votes

Every DataGridViewRow has a "Displayed" property that indicates whether or not the row is currently being shown on screen. Therefore, you can do something like this:

if(this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1].Displayed)
{
   //last rows is displayed, do what you gotta do
}
0
votes

Use a DataReadear to read some records. Then in the Scroll event of the DataGridView, check to see if the property FirstDisplayedScrollingRowIndex is getting close to the count of loaded records, use the DataReader again to fetch another bunch of rows and so on.