WPF DataGrid v快速,分组v慢。如何不使用分组显示分组行 [英] WPF DataGrid v fast, grouping v slow. How to display group rows without using grouping

查看:216
本文介绍了WPF DataGrid v快速,分组v慢。如何不使用分组显示分组行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF DataGrid,它显示的数据集具有60列以上以及最多10000s行。 DataGrid 非常快速加载并完整地处理它们。

I have a WPF DataGrid which is displaying data sets with more than 60 columns and anything up to 10000s of rows. The DataGrid loads the complete datasets very quickly and handles them well.

colA colB colC colD colE ... 

 1    2     3    4    5  
 5    6     7    8    9
 2    3     4    3    4  
 1    2     3    4    5  
 5    6     7    8    9
 2    3     4    3    4   

但是将行分为几组。我需要显示一个为文本字符串的组标题,然后才能展开/折叠组。

However the rows are split into groups. I need to display a group header that is a text string and to be able to expand/collapse the groups.

我可以对看起来像的DataGrid使用分组很好,但最初显示大型组的操作非常慢

I can use grouping for the DataGrid which looks fine but is incredibly slow to initially display large groups.

 colA colB colC colD colE ... 
^ group title A
  1    2     3    4    5  
  5    6     7    8    9
  2    3     4    3    4  
^ group title B
  1    2     3    4    5  
  5    6     7    8    9
  2    3     4    3    4  

我可以通过在DataGrid外部添加一个带有组描述的额外列来对自己进行分组。然后,我可以通过更改提供给网格的数据集来折叠/展开任何组。 非常快,但它看起来很垃圾,因为它浪费了很多空间,尤其是长标题时。

I can do the grouping myself externally to the DataGrid by adding an extra column with the group description in it. I can then collapse/expand any groups by changing the dataset provided to the grid. That is very fast, but it looks rubbish as it wastes a lot of space especially with long group titles.

group          colA colB colC colD colE ...  
 group title A
                1    2     3    4    5  
                5    6     7    8    9
                2    3     4    3    4  
 group title B
                1    2     3    4    5  
                5    6     7    8    9
                2    3     4    3    4  

我想要的是两全其美的方法,即又快又漂亮
可以像显示DataGrid一样显示数据,而
却可以在外部进行分组。

What I want is the best of both worlds i.e. fast and pretty, to be able to display the data as if the DataGrid was grouping, but to do the grouping externally.

  colA colB colC colD colE ... 
 ^ Very long comment about the data ...
   1    2     3    4    5  
   5    6     7    8    9   
   2    3     4    3    4  
 ^ Another arbitrarily long comment...
   1    2     3    4    5  
   5    6     7    8    9  
   2    3     4    3    4  

任何想法h ow我可以这样显示我的组标题吗?

Any idea how I can display my group headers that way?

推荐答案

这是一个老问题,但是我在此处添加答案以供将来参考:

This is an old question, however I add the answer here for future references:

自.Net 4.5起,Microsoft已添加 IsVirtualizingWhenGrouping 属性。将 DataGrid 的此属性设置为 True 可以解决此问题。

Since .Net 4.5, Microsoft has added IsVirtualizingWhenGrouping property. Setting this property of the DataGrid to True solves this issue.

<DataGrid VirtualizingPanel.IsVirtualizingWhenGrouping="True">

来源:此博客 (显然该博客不再可用)

Source: This blog (Apparently this blog isn't available anymore)

这篇关于WPF DataGrid v快速,分组v慢。如何不使用分组显示分组行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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