Back to Devexpress

XRCrossTabCell.BeforePrint Event

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-crosstab-dot-xrcrosstabcell-1a0a0f46.md

latest5.6 KB
Original Source

XRCrossTabCell.BeforePrint Event

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

Namespace : DevExpress.XtraReports.UI.CrossTab

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public event CrossTabCellPrintEventHandler BeforePrint
vb
Public Event BeforePrint As CrossTabCellPrintEventHandler

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.

csharp
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;
}
vb
Imports System.Drawing
Imports DevExpress.XtraReports.UI.CrossTab
' ...
Private Sub xrCrossTabCell3_BeforePrint(ByVal sender As Object, ByVal e As CrossTabCellPrintEventArgs)
    ' Obtain the current cell.
    Dim cell As XRCrossTabCell = DirectCast(sender, XRCrossTabCell)

    ' Change the cell's foreground color if its value exceeds 3000.
    Dim value As Decimal = cell.GetCurrentFieldValue(Of Decimal)("Extended Price")
    If value > 3000 Then
        cell.ForeColor = Color.Red
    Else
        cell.ForeColor = Color.Black
    End If

    ' Apply different background colors to odd and even rows.
    If e.GroupRowIndex Mod 2 = 0 Then
        cell.BackColor = Color.LightCyan
    Else
        cell.BackColor = Color.White
    End If
End Sub

See Also

XRCrossTabCell Class

XRCrossTabCell Members

DevExpress.XtraReports.UI.CrossTab Namespace