Skip to main content
A newer version of this page is available. .

Grid-Based Report Generation

  • 3 minutes to read

Grid-based Report Generation allows you to get a report with the same data, design, and layout as your GridControl currently displays. End users can customize an automatically built report design without having to build a report from scratch.

Note

Grid-based Report Generation works only with the TableView.

You can enable Grid-based Report Generation at runtime (in code) or using behaviors without additional coding (in XAML).

Enabling Grid-Based Report Generation at Runtime

The example below demonstrates how to initialize and open the Report Designer at runtime.

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" 
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" 
    x:Class="DXGridSample.MainWindow"
    Title="MainWindow" 
    Height="350" 
    Width="525">
    <DockPanel>
        <dxb:ToolBarControl DockPanel.Dock="Top">
            <dxb:BarButtonItem Content="Open Report Designer" ItemClick="BarButtonItem_ItemClick"/>
        </dxb:ToolBarControl>
        <dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew">
            <dxg:GridControl.View>
                <dxg:TableView x:Name="tableView" ShowTotalSummary="True" />
            </dxg:GridControl.View>
        </dxg:GridControl>
    </DockPanel>
</Window>
using System.Windows;
using System.Collections.ObjectModel;
using DevExpress.XtraReports.UI;
using DevExpress.Xpf.Grid.Printing;
using DevExpress.XtraExport.Helpers;
using DevExpress.Xpf.Reports.UserDesigner;

namespace DXGridSample {
    public partial class MainWindow : Window {
        ...
        void BarButtonItem_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
            ShowDesigner(tableView);
        }
        // Initializes and runs a Report Designer.
        public static void ShowDesigner(IGridViewFactory<ColumnWrapper, RowBaseWrapper> factory) {
            var report = new XtraReport();
            ReportGenerationExtensions<ColumnWrapper, RowBaseWrapper>.Generate(report, factory);
            ReportDesigner reportDesigner = new ReportDesigner();
            reportDesigner.Loaded += (s, e) => {
                reportDesigner.OpenDocument(report);
            };
            reportDesigner.ShowWindow(factory as FrameworkElement);
        }
    }
}

WPF_Grid_Reporting1.png

Enabling Grid-Based Report Generation Using Behaviors

To enable grid-based reporting using behaviors, attach the GridReportManagerService to a TableView, then attach ReportManagerBehavior to a ribbon or bar item and bind its ReportManagerBehavior.Service property to GridReportManagerService.

The code sample below demonstrates how to enable grid-based report generation in XAML only, without any additional coding.

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" 
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" 
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" 
    xmlns:dxrudex="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesignerextensions" 
    x:Class="DXGridSample.MainWindow"
    Title="MainWindow" 
    Height="350" Width="525">
    <DockPanel>
        <dxb:ToolBarControl DockPanel.Dock="Top" >
            <dxb:BarSplitButtonItem Glyph="{dx:DXImage Image=Print_16x16.png}">
                <dxmvvm:Interaction.Behaviors>
                    <dxrudex:ReportManagerBehavior Service="{Binding ElementName=reportManagerService}"/>
                </dxmvvm:Interaction.Behaviors>
            </dxb:BarSplitButtonItem>
        </dxb:ToolBarControl>
        <dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew">
            <dxg:GridControl.View>
                <dxg:TableView x:Name="view" ShowTotalSummary="True">
                    <dxmvvm:Interaction.Behaviors>
                        <dxrudex:GridReportManagerService x:Name="reportManagerService" />
                    </dxmvvm:Interaction.Behaviors>
                </dxg:TableView>
            </dxg:GridControl.View>
        </dxg:GridControl>
    </DockPanel>
</Window>

WPF_Grid_Reporting2.png

Limitations

  • If the GridControl works in master-detail mode, only the master view is displayed within the Report Designer. End users can manually add detail rows to report.
  • The merged grid cells are exported as separate cells.
  • Custom grouping, custom sorting, and custom summaries are not applied to report design.
See Also