开发者

How we create pages to show records from a DataTable in a DataGrid in WPF?

I have a DataTable for example wi开发者_开发问答th 30 rows, but i only want to show from 0 to 10. And if the user clicks in a button (like forward or next), it will clear the Items in the DataGrid and shows between 10 and 20.

What i want is to separate records in a Collection of pages and then to show in DataGrid and control them with two buttons (forward or next, and backward or previous). It can be done? How?

In this case if it's possibly to separate the records in pages, we will not have problems to update the table in the DataBase?

And other thing, if i want to filter the records in my DataGrid, like if we have a TextBox, we type something, and then the DataGrid only shows the records with some value similar to that we have typed in the TextBox. Can it be done?


Try programmatically databinding to your DataGrid:

var perPage = 10;
var page = 2;

//Will bind rows 11-20 to the DataGrid
dataGrid.DataContext = DataTable.Rows.OfType<DataRow>().Skip(page*perPage).Take(perPage);

You'll need some simple buttons or links to implement operations like First, Previous, Next, Last, or page numbers to jump to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜