简体   繁体   English

使用数据绑定(winforms)时如何在datagrid中实现分页功能?

[英]How to implement paging function in the datagrid when using data binding (winforms)?

I use data binding to control the datagrid, which connect to database table directly, what I want to do now is to implement the pager function on the datagrid, which I can only load 20 records from Database into memory, and display them. 我使用数据绑定来控制数据网格,该数据网格直接连接到数据库表,我现在要做的是在数据网格上实现分页器功能,我只能将20条记录从数据库加载到内存中并显示它们。 What do I know now is the the data binding will load all the records into database and then do some filtering and display in the control.. any suggestion ? 我现在知道的是,数据绑定会将所有记录加载到数据库中,然后进行一些过滤并显示在控件中。有什么建议吗?

Basicaly you have to run your datagrid in virtual mode, tell the grid how many rows there are in your recordset and then react to the CellValueNeeded-event. 基本上,您必须在虚拟模式下运行数据网格,告诉网格记录集中有多少行,然后对CellValueNeeded事件做出反应。 We implemented caching follwing this example on msdn . 我们在msdn上跟随此示例实施了缓存。

You need to load 20 records at a time in your data source, ie you have to implement paging yourself. 您需要一次在数据源中加载20条记录,即您必须自己实现分页。 Each time the user requests a new page, you read the new set of records. 每次用户请求新页面时,您都会读取新的记录集。

On the SQL side, 'sql paging' will get you lots of results from your favorite search engine and here is an example . 在SQL方面,“ SQL分页”将从您喜欢的搜索引擎中获得很多结果,下面是一个示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM