WPF DataGrid v fast, grouping v slow. How to display group lines without using grouping

I have a DataGrid WPF that displays datasets with over 60 columns and a total of up to 10,000 rows. DataGrid quickly loads complete datasets and processes 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, strings are divided into groups. I need to display the group header, which is a text string, and be able to expand / collapse the groups.

I can use grouping for a DataGrid, which looks great , but 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 

I can group myself externally in a DataGrid by adding an extra column with a description of the group in it. Then I can collapse / expand any groups by changing the dataset provided to the grid. It's very fast , but it looks like trash as it spends a lot of space, especially with long band names.

 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 

What I want is the best of both worlds, i.e. quickly and beautifully , to be able to display data as if the DataGrid grouping were grouped, but for external grouping.

  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 

Any idea how I can display the headings of my groups this way?

+4
source share
3 answers

It probably loads fast due to the use of virtualization. This means that it only loads visible elements on the screen, and not all 10,000 rows and 60 columns. I assume that when grouping it should load everything, which is why you experience a slowdown.

To fix this, I would probably investigate creating my own control (with virtualization) and pre-group the data. Perhaps bind ItemControl to the grouped data, enable the expander, and when the group is expanded, get data only for this group and load it into another control. You can use Grid.IsSharedScopeSize and SharedSizeGroup to maintain column consistency.

+1
source

I am working on the same issue. WPF Datagrid cannot be virtualized when grouped, as this is a limitation of the Expander control used to represent groups that cannot be virtualized by themselves (as using ItemPresenter, not ItemsControl).

A workaround is this (scroll down to Fake grouping using ViewModel). In this blog post, the author implements groups in the view model because the data hierarchy and group headers are displayed as a custom styled string. Thus, all its ranks are without extensions or groups. This can allow you to virtualize and get the performance you need.

I am studying it now.

+1
source

This is an old question, however I am adding an answer here for future references:


Starting with .Net 4.5, Microsoft has added the IsVirtualizingWhenGrouping property. Setting this property from DataGrid to True solves this problem.

 <DataGrid VirtualizingPanel.IsVirtualizingWhenGrouping="True"> 

Source: This Blog

0
source

All Articles