windowsforms-devexpress-dot-xtragrid-dot-gridcontrol-cbddbfa5.md
Prints the grid control’s GridControl.DefaultView (the GridControl.MainView or the currently maximized detail View) without showing a print preview or print dialog.
Namespace : DevExpress.XtraGrid
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
public void Print()
Public Sub Print
The grid control’s data can be printed/exported if the XtraPrinting Library is available. To check if this library is available, use the GridControl.IsPrintingAvailable property.
Print options can be customized via a View’s BaseView.OptionsPrint property.
To show a print preview window, use the BaseView.ShowPrintPreview or BaseView.ShowRibbonPrintPreview method.
To select a printer and then print the grid control’s data, use the GridControl.PrintDialog method.
See Printing Overview to learn more.
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.
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();
}
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
See Also