Skip to main content

IDocumentModifier.GetPageIndexByID(Int64) Method

Returns the index of the page whose Page.ID is specified as a parameter.

Namespace: DevExpress.XtraReports

Assembly: DevExpress.Printing.v23.2.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

int GetPageIndexByID(
    long id
)

Parameters

Name Type Description
id Int64

The page ID.

Returns

Type Description
Int32

The page index that corresponds to the page ID passed as a parameter.

Remarks

To use the GetPageIndexByID method, get a required page’s ID beforehand. For example, you can use the XRControl.PrintOnPage event to get the ID of the page on which a particular control is contained. The example below demonstrates how to insert another report’s pages at a particular position. This position is the first page that includes the “CategoryName” label.

public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport {
    //...
    long? categoryStartPageID;
    private void XtraReport1_AfterPrint(object sender, EventArgs e) {  
        //Create the 2nd report and generate its document.
        XtraReport2 report2 = new XtraReport2();
        report2.CreateDocument();

        if(IsDisposed || categoryStartPageID == null)
            return;
        // Add the 2nd report's pages alternating them with the 1st report pages,
        // starting from the 'categoryStartPageID' page
        ModifyDocument(x => {
            int categoryStartPageIndex = x.GetPageIndexByID(categoryStartPageID.Value);
            categoryStartPageID = null;

            for(int i = 0; i < report2.Pages.Count; i++) {
                int insertIndex = categoryStartPageIndex + 1 + i * 2;
                if(insertIndex >= x.PageCount)
                    break;
                x.InsertPage(insertIndex, report2.Pages[i]);
            }
        });
    }
    private void lbCategoryName_PrintOnPage(object sender, PrintOnPageEventArgs e) {
        if(IsDisposed || categoryStartPageID != null)
            return;
        categoryStartPageID = Pages[e.PageIndex].ID;
    } 
}

Note

The Page.Index property is not recommended for this scenario because it can change during document generation.

Note

A reference to a page is not recommended in this scenario because it changes if you use caching during document generation (see CachedReportSource).

See Also