Reputation: 25
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?)
Upvotes: -2
Views: 765
Reputation: 25
So this is how I solved the problem
public async Task<IPagedList<DataRowView>> GetPagedListAsync(int pageNumber = 1, int pageSize = 6)
{
return await Task.Factory.StartNew(() =>
{
//Create a list of the rows in the DataView
List<DataRowView> li = (from DataRowView row in transactionView select row).ToList();
//Return a collection of the created list
return li.AsEnumerable().ToPagedList(pageNumber, pageSize);
});
}
Upvotes: 0