如何在DataGrid中显示大量行 [英] How to display a large number of rows in a DataGrid

查看:85
本文介绍了如何在DataGrid中显示大量行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF DataGrid,它是从DataTable中填充的。到目前为止,我的记录从未超过200个左右,因此DataGrid的填充非常完美。但是,我现在必须添加对大型数据库的支持。因此,我想到向用户显示200条记录,然后允许他按下某种按钮,以显示下一个200条,依此类推。这样可以更快地加载DataGrid。

I've got a WPF DataGrid which I am populating from a DataTable. Up till now, I never had more than 200 or so records, so the DataGrid was populated flawlessly. However, I must now add support for larger databases. Thus, I thought of showing the user 200 records, and then allowing him to press a button of some sort, to display the next 200 and so on. This is so that I would load the DataGrid faster.

什么是最好的方法?我在ASP.NET中有分页的经验,但是在WPF中从来没有这样的要求。

What would be the best approach for this? I have some experience with paging in ASP.NET, but I have never had a requirement like this in WPF.

这是我的DataGrid代码:

This is my DataGrid code:

<DataGrid Name="dgResults" 
                  IsReadOnly="True"
                  AutoGenerateColumns="True"
                  AllowDrop="False"
                  CanUserAddRows="False"
                  CanUserDeleteRows="False"
                  CanUserReorderColumns="False"
                  CanUserResizeColumns="False"
                  CanUserResizeRows="False"
                  CanUserSortColumns="False"
                  Margin="15,10,10,10"
                  Visibility="Collapsed" 
                  ItemsSource="{Binding}"/>

绑定:

dgResults.DataContext = dtResults.AsDataView();


推荐答案

回避问题的一种方法是提供具有一些搜索条件的用户,他们可以使用这些条件来查找特定的结果。至少,除非有必要,否则用户通常不会翻阅成千上万个结果。您可以通过仅返回任何给定搜索的前X个结果来利用这一点。您可以使用TSQL SELECT TOP 200 * 或如果使用linq 限制查询返回的结果量。Take(200)

A way of side-stepping the issue is to provide the user with some search criteria with which they can look for specific results. Users, generally at least, don't page through thousands of results unless they have to. You leverage this by returning only the top X results for any given search. You can limit the amount of results your query returns by using the TSQL SELECT TOP 200 * or if you're using linq .Take(200)

这篇关于如何在DataGrid中显示大量行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆