I have a large database and anytime I try to load it to the DataGridView, the UI hangs. I tried to use a BackGroundWorker for the job but that was no use. I therefore decided to use pagination (Thanks to a tutorial from FoxLearn).
My problem is that I have been unable to implement pagination using a DataView. I tried implementing it on my DataTable and I still faced the same problem.
Below is my attempted code:
int pageNumber = 1;
IPagedList<DataView> list;
DataView transactionView = analyticsDataTable.DefaultView;
private async void startPagination()
{
list = await GetPagedListAsync();
backBtn.Enabled = list.HasPreviousPage;
forwardBtn.Enabled = list.HasNextPage;
AccountDGV.DataSource = list.ToList();
pageLbl.Text = String.Format("Page {0} of {1}", pageNumber, list.PageCount);
}
public async Task<IPagedList<DataView>> GetPagedListAsync(int pageNumber = 1, int pageSize = 10)
{
return await Task.Factory.StartNew(() =>
{
return transactionView.ToPagedList(pageNumber, pageSize);
});
}
The error to the above code is:
'DataView' does not contain a definition for 'ToPagedList' and no accessible extension method 'ToPagedList' accepting a first argument of type 'DataView' could be found (are you missing a using directive or an assembly reference?)
So this is how I solved the problem