Generate a Grid-Based Report

  • 2 minutes to read

You can generate a Grid-based Report with the same data, appearance, and layout as in the displayed GridControl. End users can customize a Report appearance.

NOTE

You can generate a Grid-based Report only from the TableView.

Generate a Report at Runtime

The following example demonstrates how to initialize and open the Report Designer in code. To use this example in your project, add references to the DevExpress.Xpf.ReportDesigner.v20.1 and DevExpress.XtraReports.v20.1 assemblies.

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);
        }
    }
}

Use Behaviors to Generate a Report

To initialize and open the Report Designer in XAML:

  1. Add reference to the DevExpress.Xpf.ReportDesigner.v20.1 assembly.
  2. Attach the GridReportManagerService to a TableView.
  3. Attach the ReportManagerBehavior to a ribbon or bar item.
  4. Bind the ReportManagerBehavior.Service property to GridReportManagerService.
<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>

Limitations

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