views:

1508

answers:

3

I'm using the WPF DataGrid from CodePlex and I need to get Virtualization to work with grouping.

This question is on topic and points to an MSDN Example but it only covers ListControls with with simple (i.e. single 'column') DataTemplates.

Grouping and Virtualization seems like a pretty common use case for a Grid. Is there a standard/recommended/simple way of getting this going?

A: 

Check out this tutorial on Data Virtualization in WPF on CodePlex http://www.codeproject.com/KB/WPF/WpfDataVirtualization.aspx

Tawani
So that tutorial is mainly about Data Virtualization and the part about UI Virturalization does not handle the core problem I need to solve which is Grouping.With Grouping enabled UI Virualization breaks.
Jan Bannister
A: 

As you said, enabling Grouping will disable UI virtualization.

I don't think you'll find an easy way to solve this problem. I'd recommend you to check one of the available WPF DataGrid such as the XCeeed one that might have this feature built in their control.

Jalfp
I know that the other grids have these features to some extent but I'd prefer to use the WPF CodePlex grid as it will be standard and all the other grids are crap in different ways.
Jan Bannister
+2  A: 

There is no built-in feature that allows you to enable UI Virtualization when grouping is enabled in a ListView or DataGrid, If you think about it for a second it also makes sense. How is the DataGrid to group items that do not exist. To apply grouping the control would need to load the whole collection wich would defeat the whole purpose of virtualization. The best you can probably do is to provide some sort of virtualization in your viewmodel (the object you bind agains) in that you provide only the data that is currently needed plus some sort of generic data about the amount of data that exists and then fake the view yourself.

With grouping it could go something like this: When grouping is enabled initially all groups would be collapsed. So your viewmodel would only have to provide one item for each group that there is. Just to make sure that the view contains all exisiting groups. As soon as the user expands one group the ViewModel would dynamically refill the items for that group. This is a very simple and basic way of virtulization and not optimal but it might be a good starting point to. It is just to illistrate the approach.

bitbonk
I disagree that grouping intrinsically breaks UI Visualization. If you think about it, what you are taking about is Data Visualization, which I don't care about.There is a valid point to be made around groups being forced to be the same height as the rows they contain. Which would simplify height layout calculations.
Jan Bannister