Skip to main content

XRCrossTabCell.BeforePrint Event

Occurs before a Cross Tab cell is printed in a report document.

Namespace: DevExpress.XtraReports.UI.CrossTab

Assembly: DevExpress.XtraReports.v24.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public event CrossTabCellPrintEventHandler BeforePrint

Event Data

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

Property
GroupColumnIndex
GroupRowIndex

Remarks

The BeforePrint event occurs when the report’s CreateDocument method is called (internally from other methods or explicitly). This event is raised with other events in the following order:

See Report Events for more information.

The order in which the BeforeEvent event occurs for different controls on a page is undefined. If you want to change a control depending on another control in the created document, you should handle the PrintOnPage event, determine the necessary values (size, location) in the created document, adjust the other control, and then recreate the document.

Handle this event to change the cell’s properties before it is printed. Use the event argument’s GroupRowIndex and GroupColumnIndex properties to identify indexes of the current row/column within a group. You can create a conditional expression that specifies different settings for even and odd rows/columns.

You can also call the XRCrossTabCell.GetCurrentFieldValue method to obtain the current value of the specified data source field. If you do not want to cast the returned object, use the XRCrossTabCell.GetCurrentFieldValue<T> method, which returns a strongly typed object.

Note

This event does not have any relation to the actual print process. To manage print settings, handle the PrintingSystemBase.StartPrint event instead.

The BeforePrint event is not raised when you export the document to any available format because the export operation does not recreate the report document.

Example

This example demonstrates how to handle a Cross Tab cell’s BeforePrint event and customize the cell’s appearance based on its current value and row index.

using System.Drawing;
using DevExpress.XtraReports.UI.CrossTab;
// ...
private void xrCrossTabCell3_BeforePrint(object sender, CrossTabCellPrintEventArgs e) {
    // Obtain the current cell.
    XRCrossTabCell cell = (XRCrossTabCell)sender;

    // Change the cell's foreground color if its value exceeds 3000.
    decimal value = cell.GetCurrentFieldValue<decimal>("Extended Price");
    if (value > 3000)
        cell.ForeColor = Color.Red;
    else cell.ForeColor = Color.Black;

    // Apply different background colors to odd and even rows.
    if (e.GroupRowIndex % 2 == 0)
        cell.BackColor = Color.LightCyan;
    else cell.BackColor = Color.White;
}

See Also