Skip to main content

DevExpress v24.1 Update — Your Feedback Matters

Our What's New in v24.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.v24.1 and DevExpress.XtraReports.v24.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.v24.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.

View Example: Use the GridReportManagerService to Implement the Report Management Functionality

<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">
                    <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 master-detail mode, only the master View is displayed in the Report Designer. 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.
  • The report displays summaries from the top summary panel below data rows.
See Also