WPF How To: Endless scrolling of 2mil. records using BackgroundWorker and LINQ to SQL

Monday, February 02, 2009 by Vladimir Enchev | Comments 2

I’ve made small demo how to create easily endless scrolling of almost 2 mil. records (exact count is 1770607) using RadGridView for WPF.

When you reach the bottom of the vertical scrollbar, more data will be retrieved on-the-fly from the data-base server:

Untitled

For asynchronous data loading you can use BackgroundWorker:

BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerAsync();

…

void worker_DoWork(object sender, DoWorkEventArgs e)
{ 
NorthwindDataContext context = new NorthwindDataContext(); queryable = from o in context.Orders
from od in context.Order_Details select new { od.OrderID, od.ProductID, od.UnitPrice, od.Quantity, od.Discount, o.CustomerID, o.EmployeeID, o.OrderDate };
}

and on GridViewScrollViewer VerticalScrollEnded event you can get more records:

void ScrollOwner_VerticalScrollEnded(object sender, System.Windows.Controls.Primitives.ScrollEventArgs e)
{
    if (((ScrollBar)e.OriginalSource).Maximum == e.NewValue)
    {
        pageSize = pageSize + 50;
        worker.RunWorkerAsync();
} }

In this demo you can find also how to cancel the default grid sorting and perform your own sorting and how to make nice loading image for your asynchronous operations.

Enjoy!

[Download]

2 Comments

Add comment

  1. Formatting options
       
     
     
     
     
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)