We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to detect when user has scrolled to bottom of list in order to run query & append more rows to list

My application runs a query on MS Azure SQL Server DB which can return many hundreds of results. I had been inserting each of these results into a MultiColumnComboboxControl. At the advice of somebody with more DB design experience than myself I modified the query to return the results in blocks of 50. The query therefore has parameters to specify the record offset to begin retrieval at and how many records should be retrieved. This is being called upon application launch with 0, 50 for the aforementioned parameters meaning that when the user first clicks on the combobox the list has 50 rows.

I would like to add code that detects when the user has scrolled to the bottom of the list such that I can call the query again this time passing 50, 50 to grab the next batch of 50 results which would be appended to the current list.

This is common practice with websites and I'm hoping there's a way to accomplish the same with a WinForms application. Does anybody know how I might go about doing this because I'm not finding a suitable event to, for example, determine the position of the vertical scrollbar.

If this isn't possible has anybody else come up with a workable way of doing this?

Thank you,

Jason.

3 Replies

DV Duraimurugan Vedagiri Syncfusion Team May 18, 2020 12:47 PM UTC

Hi Feded,

Thanks for using syncfusion products.

We have analyzed the reported query “load the data when scrolling move to last row index”. In the GridControl.QueryCellInfo event handler with help e.RowIndex property you can determine the last row of record while scroll. Please refer the below code snippet.

Code Snippet
private int limit = 20, maximumrowcount = 20, offset = 0; 
DataTable table = new DataTable(); 
SqlCeDataAdapter adapter; 
SqlCeConnection conn; 
 
void Form1_Load(object sender, EventArgs e) 
{ 
    //Access the database and get the NorthWind 
    conn = new SqlCeConnection(); 
    conn.ConnectionString = "Data Source = " + (@"..\..\" + "NorthwindIO_3.5.sdf"); 
    conn.Open(); 
    LoadData(); 
    GridControl grid = SampleControl1.multiColumnBoundCombo.ListBox.Grid; 
    grid.QueryCellInfo += Grid_QueryCellInfo; 
} 
 
 
private void LoadData() 
{ 
    table.Clear(); 
    adapter = new SqlCeDataAdapter("SELECT CompanyName, ContactName FROM Customers ORDER BY CompanyName", conn); 
    adapter.Fill(offset, maximumrowcount, table); 
    //Bind the Data Table with the MultiColumnBoundCombobox DataSource 
    this.SampleControl1.multiColumnBoundCombo.DataSource = table; 
    this.SampleControl1.multiColumnBoundCombo.SelectedIndex = 1; 
    adapter.Dispose(); 
    conn.Close(); 
} 
 
private void Grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
{ 
    //Determine bottom of the record. 
    if (e.RowIndex == maximumrowcount && e.ColIndex == 0) 
    { 
        maximumrowcount += limit; 
        LoadData(); 
    } 
} 

Sample : https://www.syncfusion.com/downloads/support/forum/154336/ze/MultiColumnCombo-96939813.zip  

Please let us know if you need any further assistance

Regards,
Durai




FE feded May 21, 2020 10:46 AM UTC

Hi Durai,

Thank you very much for providing the sample code.  This is working exactly as intended.

Thanks again,

Jason.


DV Duraimurugan Vedagiri Syncfusion Team May 22, 2020 04:58 AM UTC

Hi Jason,

Thanks for your update.

We are very pleased to hear that the reported requirement is achieved at your end. Please get back to us if you need any other assistance.

Regards,
Durai


Loader.
Up arrow icon