Back to Devexpress

PrintOnPageEventArgs.PageIndex Property

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-printonpageeventargs-007d5387.md

latest6.3 KB
Original Source

PrintOnPageEventArgs.PageIndex Property

Gets the index of the current page which the control will be printed on.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public int PageIndex { get; }
vb
Public ReadOnly Property PageIndex As Integer

Property Value

TypeDescription
Int32

An integer value which specifies the current page index. Note that the first page’s index is equal to 0.

|

Remarks

The XRControl.PrintOnPage event is raised repeatedly for each control every time its view data is printed on the existing report page. The PageIndex property allows the index of the current page to be retrieved. Use this property to change some of the property values of a printed XRControl. Note that you’re also able to cancel the control’s printing by setting the Cancel property to true.

Example

The following example demonstrates how to use the XRControl.PrintOnPage event. The event handler below checks if an xrLabel1 is being printed on the last page (in case the PrintOnPageEventArgs.PageCount property is equal to PrintOnPageEventArgs.PageIndex minus 1), and, if yes, sets its text to “The last page!”. Otherwise, it checks if a label is being printed on the odd page, and, if yes, it cancels its printing.

csharp
using DevExpress.XtraReports.UI;
// ...

private void xrLabel1_PrintOnPage(object sender, PrintOnPageEventArgs e) {
    // Check if the label is printed on the last page.
    // Note that the PageCount property value is not valid if you
    // use the CachedReportSource component to generate a report document
    if (e.PageIndex == e.PageCount-1)
        // Set its text.
        ((XRLabel)sender).Text = "The last page!";
    else
        // Check if the label is printed on the odd page.
        if (e.PageIndex % 2 == 0)
            // Cancel its printing.
            e.Cancel = true;
}
vb
Imports DevExpress.XtraReports.UI
' ...

Private Sub OnLabelPrintOnPage(ByVal sender As Object, ByVal e As PrintOnPageEventArgs) _
Handles xrLabel1.PrintOnPage
    ' Check if the label is printed on the last page.
    If e.PageIndex = e.PageCount - 1 Then
        ' Set its text.
        CType(sender, XRLabel).Text = "The last page!"
    Else
        ' Check if the label is printed on the odd page.
        If e.PageIndex Mod 2 = 0 Then
            ' Cancel its printing.
            e.Cancel = True
        End If
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the PageIndex property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-web-cacheddocumentsource-custom-data/CS/CustomCachedDocumentSourceSerialization/CategoriesReport.cs#L27

csharp
if (cell != null && int.TryParse(cell.Text, out categoryNumber)) {
    if (!pageAdditionalData.ContainsKey(e.PageIndex)) {
        pageAdditionalData[e.PageIndex] = new List<int>();

reporting-web-viewer-document-custom-data/CS/CustomCachedDocumentSourceSerialization/CategoriesReport.cs#L27

csharp
if (cell != null && int.TryParse(cell.Text, out categoryNumber)) {
    if (!pageAdditionalData.ContainsKey(e.PageIndex)) {
        pageAdditionalData[e.PageIndex] = new List<int>();

reporting-web-cacheddocumentsource-custom-data/VB/CustomCachedDocumentSourceSerialization/CategoriesReport.vb#L32

vb
If cell IsNot Nothing AndAlso Integer.TryParse(cell.Text, categoryNumber) Then
    If Not pageAdditionalData.ContainsKey(e.PageIndex) Then
        pageAdditionalData(e.PageIndex) = New List(Of Integer)()

reporting-web-viewer-document-custom-data/VB/CustomCachedDocumentSourceSerialization/CategoriesReport.vb#L30

vb
If cell IsNot Nothing AndAlso Integer.TryParse(cell.Text, categoryNumber) Then
    If Not pageAdditionalData.ContainsKey(e.PageIndex) Then
        pageAdditionalData(e.PageIndex) = New List(Of Integer)()

See Also

PageCount

PrintOnPageEventArgs Class

PrintOnPageEventArgs Members

DevExpress.XtraReports.UI Namespace