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

SpreadsheetControl.BeforePrintSheet Event

Provides the capability to prevent printing of the required worksheets in a workbook.

Namespace: DevExpress.Xpf.Spreadsheet

Assembly: DevExpress.Xpf.Spreadsheet.v19.1.dll

Declaration

public event BeforePrintSheetEventHandler BeforePrintSheet

Event Data

The BeforePrintSheet event's data class is BeforePrintSheetEventArgs. The following properties provide information specific to this event:

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
Index Returns the index of the worksheet to be printed.
Name Returns the name of the worksheet to be printed.

Remarks

The BeforePrintSheet event is raised before a workbook is printed or exported to PDF. Use properties of the BeforePrintSheetEventArgs class to get the worksheet being printed or exported by its name or index, and set the Cancel property to true to cancel the print/export operation.

The example below demonstrates how to print the active worksheet only.

using DevExpress.Spreadsheet;
// ...

bool printActiveSheetOnly = true;
//...

private void spreadsheetControl_BeforePrintSheet(object sender, BeforePrintSheetEventArgs e)
{
  if (printActiveSheetOnly)
      // Cancel printing if the index of the worksheet to be printed is not equal to the active sheet index. 
      e.Cancel = spreadsheetControl.ActiveWorksheet.Index != e.Index;
}
See Also