private void MakePager_BigData()
{
try
{
var itemCount = new List<int>();//數據源總共多少數據的整形鏈表
int pageCount = IDList.Count / dataGridPageSize; //計算出總共多少頁
//
for (int i = 0; i < pageCount; i++)
{
itemCount.Add(i);
}
PagedCollectionView pcv = new PagedCollectionView(itemCount);//創建PagedCollectionView
if (pcv != null)
{
pcv.PageSize = 1;//設置PagedCollectionView的每頁顯示1條數據(虛擬對應的,為了和datagrid對應)
dataPager1.PageSize = 1;//設置dataPager每頁顯示1條數據(虛擬對應的,為了和datagrid對應)
this.dataPager1.Source = pcv;//設置dataPager的數據源
}
}
catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); }
}
//根據頁索引動態綁定數據源
private void dataPager1_PageIndexChanged(object sender, EventArgs e)
{
int curPageIdx = dataPager1.PageIndex;
int skipData = curPageIdx * dataGridPageSize;
List<IDData> curBindingDataSource = ((from p in IDList select p).Skip(skipData).Take(dataGridPageSize)).ToList();
dataGrid1.ItemsSource = curBindingDataSource;
}
posted on 2013-04-15 15:35
天書 閱讀(1304)
評論(0) 編輯 收藏 引用