GroupInfoCollection Class
Represents a collection of group information objects.
Namespace: DevExpress.Xpf.Printing
Assembly: DevExpress.Xpf.Printing.v24.2.dll
NuGet Package: DevExpress.Wpf.Printing
#Declaration
#Related API Members
The following members return GroupInfoCollection objects:
#Remarks
The GroupInfoCollection class represents a collection of GroupInfo objects that store group information. Its properties and methods can be used to perform common collection operations such as adding new or deleting existing items. Individual items can be accessed using indexer notation.
A collection of group information objects can be accessed via the links’s CollectionViewLink.GroupInfos property.
#Example
The following example demonstrates how to use the CollectionViewLink class to print data from a hierarchical datasource, which implements the ICollectionView interface.
For this, it is necessary to do the following:
- Assign an object, which implements the ICollectionView interface to the CollectionViewLink.CollectionView property;
- Create a DataTemplate for a single detail row and assign it to the CollectionViewLink.DetailTemplate property;
- Create a DataTemplate for a group header and assign it to the GroupInfo.HeaderTemplate property;
- Call the LinkBase.CreateDocument method to generate report pages.
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using DevExpress.Xpf.Printing;
// ...
private void button1_Click(object sender, RoutedEventArgs e) {
// Create a link and bind it to the PrintPreview instance.
CollectionViewLink link = new CollectionViewLink();
//preview.Model = new LinkPreviewModel(link);
// Create an ICollectionView object.
link.CollectionView = CreateMonthCollectionView();
// Provide export templates.
link.DetailTemplate = (DataTemplate)Resources["monthNameTemplate"];
link.GroupInfos.Add(new GroupInfo((DataTemplate)Resources["monthQuarterTemplate"]));
// Create a document.
link.CreateDocument(true);
// Show a Print Preview.
PrintHelper.ShowPrintPreviewDialog(this, link);
}
private ICollectionView CreateMonthCollectionView() {
const int monthCount = 12;
string[] monthNames = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames;
MonthItem[] data = new MonthItem[Math.Min(monthNames.Length, monthCount)];
for (int i = 0; i < data.Length; i++) {
data[i] = new MonthItem(monthNames[i], (i / 3) + 1);
}
CollectionViewSource source = new CollectionViewSource();
source.Source = data;
source.GroupDescriptions.Add(new PropertyGroupDescription("Quarter"));
return source.View;
}
public class MonthItem {
public string Name { get; private set; }
public int Quarter { get; private set; }
public MonthItem(string name, int quarter) {
Name = name;
Quarter = quarter;
}
}