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

Printing Basics

  • 3 minutes to read

This topic covers how to print a Tree List layout and show a print preview for the control.

The TreeList.ShowPrintPreview and TreeList.ShowRibbonPrintPreview methods open a window with print commands and a print preview of the current Tree List control. When using the first method, the print commands are displayed using the Bars UI, while the second method displays the print commands using a Ribbon UI. Using the Preview window, an end-user is able to customize the page settings (the page format, margins and orientation), provide a background image for pages, specify which Tree List elements must be printed, export the Tree List to various formats (PDF, HTML. XLS, Image, etc), and so on.

The TreeList.Print method prints the Tree List control immediately, without showing a preview, using the default page settings. Before calling this method, you can specify which Tree List elements must be printed. To do this, use the properties provided by the TreeList.OptionsPrint object. This object also provides settings that specify whether to expand nodes before printing, whether columns must be stretched to fit the page width, etc.

You can also use the TreeList.PrintDialog method to display the standard Print dialog, which allows you to select a printer and its settings, and then start or cancel the print operation.

The TreeList.ShowPrintPreview, TreeList.ShowRibbonPrintPreview and TreeList.Print methods provide basic printing capabilities. For information on advanced printing capabilities (e.g., setting the paper size and margins beforehand, add headers and footers to the printout, etc.), see How to: Set Paper Format and Add Custom Information to the Report when Printing/Exporting a Control.

Example

The following example demonstrates how to print a TreeList with the TreeList.Print method, and show its print preview with the TreeList.ShowRibbonPrintPreview method.

The image below shows the Preview window for a sample Tree List control. The print commands provided by this window are displayed using a Ribbon UI.

Printing the XtraTreeList_Preview

using DevExpress.XtraTreeList;
// ...

private void ShowTreeListPreview(TreeList treeList) {
    // Check whether the Tree List can be previewed.
    if (!treeList.IsPrintingAvailable) {
        MessageBox.Show("The Printing Library is not found", "Error");
        return;
    }

    // Open the Preview window.
    treeList.ShowRibbonPrintPreview();
}

private void PrintTreeList(TreeList treeList) {
    // Check whether the Tree List can be printed.
    if (!treeList.IsPrintingAvailable) {
        MessageBox.Show("The Printing Library is not found", "Error");
        return;
    }

    // Print.
    treeList.Print();
}
See Also