Skip to main content
A newer version of this page is available. .

DataViewBase.ShowPrintPreviewDialog(Window, String) Method

Creates the print document from the DataViewBase (or its inheritor) and displays a Print Preview of the document as a modal window.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v20.2.Core.dll

NuGet Packages: DevExpress.WindowsDesktop.Wpf.Grid.Core, DevExpress.Wpf.Grid.Core

Declaration

public void ShowPrintPreviewDialog(
    Window owner,
    string documentName
)

Parameters

Name Type Description
owner Window

The owner of the Print Preview.

documentName String

The name of the document displayed in the Print Preview.

Remarks

The Print Preview displays the printed document’s appearance. The Print Preview window allows end users to print the document and export it to a file in the required format.

View Example

void Print_Data(object sender, RoutedEventArgs e) {
    view.ShowPrintPreviewDialog(this, "ExamplePrint");
}

Note

You can preview, print, and export the control’s data only if the DXPrinting Library is available.

Refer to the following topics for more information on how to print data:

Example

This example shows how to preview and print/export the grid content. The grid is printed and exported using the built-in capabilities.

View Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DXGrid_PrintGrid {
    public class IssueList {
        public List<IssueDataObject> List { get; private set; }
        public IssueList() {
            List = GetIssueList();
        }
        List<IssueDataObject> GetIssueList() {
            List<IssueDataObject> data = new List<IssueDataObject>();
            data.Add(new IssueDataObject() { IssueName = "Transaction History", IssueType = "Bug", IsPrivate = true });
            data.Add(new IssueDataObject() { IssueName = "Ledger: Inconsistency", IssueType = "Bug", IsPrivate = false });
            data.Add(new IssueDataObject() { IssueName = "Data Import", IssueType = "Request", IsPrivate = false });
            data.Add(new IssueDataObject() { IssueName = "Data Archiving", IssueType = "Request", IsPrivate = true });
            return data;
        }
    }
    public class IssueDataObject {
        public string IssueName { get; set; }
        public string IssueType { get; set; }
        public bool IsPrivate { get; set; }
    }
}
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using DevExpress.Xpf.Grid;
using DevExpress.Xpf.Printing;

namespace DXGrid_PrintGrid {
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
            DataContext = new IssueList();
        }
        private void PreviewGrid(object sender, RoutedEventArgs e) {
            view.ShowPrintPreviewDialog(this);
        }
        private void ExportToXls(object sender, RoutedEventArgs e) {
            view.ExportToXlsx(@"d:\grid_export.xlsx");
        }
        private void ExportToCsv(object sender, RoutedEventArgs e) {
            view.ExportToCsv(@"d:\grid_export.csv");
        }
        private void ExportToPng(object sender, RoutedEventArgs e) {
            view.ExportToImage(@"d:\grid_export.png");
        }
    }
}
<Window x:Class="DXGrid_PrintGrid.Window1" Title="Window1" Height="300" Width="450"
    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">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew" ItemsSource="{Binding List}">
            <dxg:GridControl.View>
                <dxg:TableView x:Name="view" AutoWidth="True" />
            </dxg:GridControl.View>
        </dxg:GridControl>
        <WrapPanel Grid.Row="1" Orientation="Horizontal">
            <Button Click="PreviewGrid">
                Show Print Preview
            </Button>
            <Button Click="ExportToXls">
                Export to MS Excel
            </Button>
            <Button Click="ExportToCsv">
                Export to CSV
            </Button>
            <Button Click="ExportToPng">
                Export to an image
            </Button>
        </WrapPanel>
    </Grid>
</Window>
See Also