Print Data
- 5 minutes to read
#Print Data in Code
To print GridControl data, call one of the following methods:
Method | Description |
---|---|
Data |
Invokes the standard Print dialog that allows users to print the grid. |
Data |
Uses the default printer to print the grid. |
#Print Data with Print Preview
The Print Preview window allows users to print documents and export them to a file in the required format.
To invoke the Print Preview window, call one of the following methods:
Method | Description |
---|---|
Data |
Creates a document from the View and displays the document’s Print Preview. |
Data |
Creates a document from the View and displays the document’s modal Print Preview. |
Data |
Creates a document from the View and displays the document’s Print Preview with the Ribbon. |
Data |
Creates a document from the View and displays the document’s modal Print Preview with the Ribbon. |
#Add Print Preview to a Project
Add the DocumentPreviewControl to the window.
Specify the DocumentPreviewControl‘s name and position:
<Window ... xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="300"/> <ColumnDefinition /> </Grid.ColumnDefinitions> <dxg:GridControl Grid.Column="0" .../> <Button Grid.Column="0" Content="Print" VerticalAlignment="Bottom" Click="Button_Click_Print"/> <dxp:DocumentPreviewControl Grid.Column="1" x:Name="documentPreview1"/> </Grid>
Use the PrintableControlLink to show the GridControl in the Print Preview window:
using DevExpress.Xpf.Printing; private void Button_Click_Print(object sender, RoutedEventArgs e) { PrintableControlLink link = new PrintableControlLink(view); link.CreateDocument(); documentPreview1.DocumentSource = link; }
#Customize Appearance
Note
Printed Grid
GridControl Views have styles and templates that define printed GridControl appearance.
#Example: Change Column Header Appearance
<Window
xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys">
<Window.Resources>
<Style x:Key="customPrintColumnHeaderStyle"
TargetType="dxe:BaseEdit"
BasedOn="{StaticResource {dxgt:TableViewThemeKey ResourceKey=DefaultPrintHeaderStyle}}">
<Setter Property="Background" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
</Window.Resources>
<dxg:GridControl.View>
<dxg:TableView PrintColumnHeaderStyle="{StaticResource customPrintColumnHeaderStyle}"/>
</dxg:GridControl.View>
#Example: Bind Cell Background to a Property Value
The following code sample uses brushes specified in the Color column to paint the background of Product Name cells when you print data:
<!--
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
-->
<dxg:GridColumn FieldName="ProductName">
<dxg:GridColumn.PrintCellStyle>
<Style TargetType="dxe:TextEdit"
BasedOn="{StaticResource {dxgt:TableViewThemeKey ResourceKey=DefaultPrintCellStyle}}">
<Setter Property="Background" Value="{Binding RowData.Row.Color}"/>
</Style>
</dxg:GridColumn.PrintCellStyle>
</dxg:GridColumn>
#Example: Render Images within Data Cells with PopupImageEdit
<Window ...
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing">
<!-- ... -->
<Style x:Key="ImageColumnPrintingStyle"
TargetType="{x:Type dxe:PopupImageEdit}"
BasedOn="{StaticResource {dxgt:TableViewThemeKey ResourceKey=DefaultPrintCellStyle}}">
<Setter Property="dxp:ExportSettings.TargetType" Value="Panel"/>
<Setter Property="DisplayTemplate">
<Setter.Value>
<ControlTemplate TargetType="dxe:PopupImageEdit">
<dxe:ImageEdit Source="{Binding Path=Value}"
IsPrintingMode="True"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- ... -->
<dxg:GridColumn FieldName="Image"
PrintCellStyle="{StaticResource ImageColumnPrintingStyle}">
<dxg:GridColumn.EditSettings>
<dxe:PopupImageEditSettings/>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
To additionally customize your document, use Printing Links. For example:
To fully display visible columns on a page, use PrintableControlLink and specify the LinkBase.VerticalContentSplitting property:
To export multiple controls to the same document, use CompositeLink.
Property | Description |
---|---|
TemplatedLink.PageHeaderData / TemplatedLink.PageHeaderTemplate | Allows you to customize a page header in the output document. |
TemplatedLink.ReportHeaderData / TemplatedLink.ReportHeaderTemplate | Allows you to customize a report header in the output document. |
TemplatedLink.PageFooterData / TemplatedLink.PageFooterTemplate | Allows you to customize a page footer in the output document. |
TemplatedLink.ReportFooterData / TemplatedLink.ReportFooterTemplate | Allows you to customize a report footer in the output document. |
#Print Options
#Table View Options
Property | Description |
---|---|
Data |
Specifies whether the Summary Panel is printed. |
Data |
Specifies whether the Fixed Summary Panel is printed. |
Grid |
Specifies whether the grid is printed with all group rows expanded. |
Table |
Specifies whether printed column widths are automatically changed to allow the grid to fit the width of the report page. |
Table |
Specifies whether column headers are printed. |
Table |
Specifies whether group footers are printed. |
Base |
Allows you to hide specific columns when printing or exporting a grid. |
#Card View Options
Property | Description |
---|---|
Data |
Specifies whether the Summary Panel is printed. |
Data |
Specifies whether the Fixed Summary Panel is printed. |
Grid |
Specifies whether the grid is printed with all group rows expanded. |
Card |
Specifies whether cards in the print/export output are automatically resized horizontally to fit the report page width. |
Card |
Specifies the thickness of a frame around a card. |
Card |
Specifies the maximum number of card columns for printing/exporting. |
Base |
Allows you to hide specific columns when printing or exporting a grid. |
#TreeList View Options
Property | Description |
---|---|
Data |
Specifies whether the Summary Panel is printed. |
Data |
Specifies whether the Fixed Summary Panel is printed. |
Tree |
Specifies whether the grid is printed with all nodes expanded. |
Tree |
Specifies whether printed column width is automatically changed to allow the grid to fit the width of the report page. |
Tree |
Specifies whether column headers are printed. |
Base |
Allows you to hide columns when printing or exporting a grid. |
#Master-Detail Options
Property | Description |
---|---|
Table |
Specifies whether View details are printed. |
Table |
Specifies whether View details that don’t contain any data are printed. |
Table |
Specifies the top print detail indent separating the details. |
Table |
Specifies the bottom print detail indent separating the details. |