Custom Paging implementation in WPF toolkit datagrid

Learner
Posted by Learner under Others category on | Views : 13223
//For storing the current page number.
private int paging_PageIndex = 1;

//For storing the Paging Size. It could be n number. I am specifying 2 for test purpose.
private int paging_NoOfRecPerPage = 2;

//To check the paging direction according to use selection.

private enum PagingMode { Next = 1, Previous =2 };



private void CustomPaging(int mode)
{
int totalRecords = dt.Rows.Count;
int pageSize = paging_NoOfRecPerPage;
if (totalRecords <= pageSize) { return; }
switch (mode)
{
case (int)PagingMode.Next:
if (totalRecords > (paging_PageIndex * pageSize))
{
DataTable tmpTable = new DataTable();
tmpTable = dt.Clone();
if (totalRecords >= ((paging_PageIndex * pageSize) + pageSize))
{
for (int i = paging_PageIndex * pageSize; i < ((paging_PageIndex * pageSize) + pageSize); i++)
{
tmpTable.ImportRow(dt.Rows[i]);
}

}
else
{
for (int i = paging_PageIndex * pageSize; i < totalRecords; i++)
{
tmpTable.ImportRow(dt.Rows[i]);
}
}
paging_PageIndex += 1;
channelGrid.ItemsSource = tmpTable.DefaultView;
tmpTable.Dispose();
}
break;

case (int)PagingMode.Previous:
if (paging_PageIndex > 1)
{
DataTable tmpTable = new DataTable();
tmpTable = dt.Clone();
paging_PageIndex -= 1;
for (int i = ((paging_PageIndex * pageSize) - pageSize); i < (paging_PageIndex * pageSize); i++)
{
tmpTable.ImportRow(dt.Rows[i]);
}
channelGrid.ItemsSource = tmpTable.DefaultView;
tmpTable.Dispose();
}
break;
}
}


Call CustomPaging((int)PagingMode.Next) funtion from Button click event.

you just need to add buttons in the designer and handle click events.

Comments or Responses

Login to post response