XtraReport.ModifyDocument(Action<IDocumentModifier>) Method
Adds and/or removes the report’s document pages.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v18.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
callback | Action<IDocumentModifier> | A delegate method that allows you to modify the report document using the IDocumentModifier object passed as a parameter. |
Remarks
In the delegate method, modify the report document’s page set using the following members exposed by the IDocumentModifier object that is passed as a parameter:
PageCount
Specifies the report document’s page count.GetPageIndexByID
Use a page’s ID instead of the Index property to identify the page, because the page index can change while changing the document’s page set. Call the GetPageIndexByID method to get a page’s current index by passing the page’s ID.InsertPage
Inserts the specified page at a specified position.RemovePageAt
Removes the specified page at a specified position.
Call the ModifyDocument method when the report’s document is already created. Use the AfterPrint event or call the CreateDocument() method beforehand.
If you use the ModifyDocument method to extend a report document with pages from another document, create the other document using the CreateDocument() method beforehand.
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;
}
}
Tip
Use the CachedReportSource/CachedReportSourceWeb component’s CreateDocument and ModifyDocument methods to merge reports that include a large amount of data.
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ModifyDocument(Action<IDocumentModifier>) method.
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.