[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
   [Collapse]Getting Started
     Lesson 1 - Create Your First Report
     Lesson 2 - Create a Grouped Report with a Document Map
     Lesson 3 - Use Your Grid Control's Layout to Create a Report
   [Expand]Fundamental Concepts
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Lesson 3 - Use Your Grid Control's Layout to Create a Report

This tutorial describes how to use the DXPrinting library for WPF to implement a tabular report based on the content and structure of a GridControl.

To create a report based on the content of the grid control, do the following.

Expanded Create a New Project and Provide Data

  1. Start Microsoft Visual Studio (2008, 2012, 2013, 2015 or 2017).
  2. Start a new project by pressing CTRL+SHIFT+N. In the invoked New Project dialog, select WPF Application, enter the name of the application, and click OK.

  3. Implement the data source. In this tutorial, use the same data source implementation that you used in Lesson 1 - Create Your First Report.

Expanded Create a Grid and Bind it to Data

  1. Open the Toolbox panel (by pressing CTRL+ALT+X), and drop the GridControl from the DX.18.2.Data & Analytics tab onto the form.

  2. Handle the Loaded event of the main window. In the event handler, bind your grid to the data source and generate the column layout, as illustrated in the following code.

  3. To format the displayed data, handle the GridControl.CustomColumnDisplayText event of the grid control.

    The following code illustrates how to apply currency formatting to the UnitPrice column.

Expanded Create a Report

DXPrinting provides a special link type - PrintableControlLink - for printing the GridControl and the PivotGridControl.

To print the content of the grid control, add a button to the main form (named Print) and handle its System.Windows.Controls.Primitives.ButtonBase.Click event. In the event handler, create a printing link.

Unlike the previous lessons, where the document preview control was embedded into the main form, this tutorial will show you how to publish the resulting report in a separate document preview window created dynamically.

To do this, call the corresponding method of the PrintHelper class. The following code sample demonstrates how to use the PrintHelper.ShowRibbonPrintPreview method to show a print preview with a ribbon toolbar.

Expanded View the Result

You are now ready to create a report that reflects the structure of the data as shown in the grid control. Run the application...

...and click Print to view the document preview. The report is displayed in a new window.

Is this topic helpful?​​​​​​​