Back to Devexpress

GridControl.ShowPrintPreview() Method

windowsforms-devexpress-dot-xtragrid-dot-gridcontrol-4dbf4836.md

latest6.0 KB
Original Source

GridControl.ShowPrintPreview() Method

Opens the Print Preview window with a Bars UI.

Namespace : DevExpress.XtraGrid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
public void ShowPrintPreview()
vb
Public Sub ShowPrintPreview

Remarks

The ShowPrintPreview method shows a print preview of the data displayed by the Grid Control’s GridControl.DefaultView (the GridControl.MainView or the currently maximized detail View). The opened print preview window is built using a Bars UI. To display the Print Preview window with a Ribbon UI, use the GridControl.ShowRibbonPrintPreview method.

The grid control can be previewed and printed if the XtraPrinting Library is available. To check if printing and previewing the grid control is allowed, use the GridControl.IsPrintingAvailable property.

To print the data without showing a print preview, use GridControl.Print or GridControl.PrintDialog.

See Printing Overview to learn more.

Example

The following example demonstrates how to print a Grid Control or show its Print Preview. To do this, you should use either the GridControl.Print or GridControl.ShowPrintPreview methods.

Note

The Grid Control can be printed and previewed only if the XtraPrinting Library is available. To verify that printing the Grid is possible, use the GridControl.IsPrintingAvailable property.

When printing a Grid, the current print settings will be used to represent a Grid. Note that you can access and change these settings via the GridView.OptionsPrint, BandedGridView.OptionsPrint or CardView.OptionsPrint properties.

csharp
using DevExpress.XtraGrid;
// ...

private void ShowGridPreview(GridControl grid) {
    // Check whether the GridControl can be previewed.
    if (!grid.IsPrintingAvailable) {
        MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
        return;
    }

    // Open the Preview window.
    grid.ShowPrintPreview();
}

private void PrintGrid(GridControl grid) {
    // Check whether the GridControl can be printed.
    if (!grid.IsPrintingAvailable) {
        MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
        return;
    }

    // Print.
    grid.Print();
}
vb
Imports DevExpress.XtraGrid
' ...

Sub ShowGridPreview(ByVal grid As GridControl)
   ' Check whether the GridControl can be previewed.
   If Not grid.IsPrintingAvailable Then
      MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error")
      Return
   End If

   ' Opens the Preview window.
   grid.ShowPrintPreview()
End Sub

Sub PrintGrid(ByVal grid As GridControl)
   ' Check whether the GridControl can be printed.
   If Not grid.IsPrintingAvailable Then
      MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error")
      Return
   End If

   ' Print.
   grid.Print()
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ShowPrintPreview() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-print-custom-draw-content/CS/MyXtraGrid/Form1.cs#L47

csharp
{
    myGridControl1.ShowPrintPreview();
}

winforms-grid-print-custom-draw-content/VB/MyXtraGrid/Form1.vb#L46

vb
Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton1.Click
    myGridControl1.ShowPrintPreview()
End Sub

See Also

IsPrintingAvailable

Print()

PrintDialog()

ShowRibbonPrintPreview()

Printing Overview

GridControl Class

GridControl Members

DevExpress.XtraGrid Namespace