Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]Welcome to DevExpress .NET Documentation
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Collapse]Printing-Exporting
   [Expand]Overview
   [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]Concepts
   [Expand]Examples
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Diagram Control
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

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, 2010, 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.17.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?​​​​​​​