A newer version of this page is available. Switch to the current version.

CompositeLink Class

A composite link that can be used to combine several printing links together into a composite document.

Namespace: DevExpress.XtraPrintingLinks

Assembly: DevExpress.XtraPrinting.v18.2.dll

Declaration

Remarks

Use the CompositeLink class to combine different printing links into one document and then show its Print Preview, print or export the resulting document.

To do this, add links to be combined together to the collection returned by the CompositeLinkBase.Links property, and then call either the Link.ShowPreview method to preview a document, or the Link.Print method to send it to a printer.

It is impossible to create a separate document for a printing link that has been added to a composite link's repository (only the composite document can be created out of all included links at one time).

Examples

This example demonstrates how to combine reports in code. It uses event handlers to create detail areas of combined reports.

CombineReports

In a real task, you can use event handlers to create any area of a report, enclosed within the composite report, except for marginal headers and footers, which belong solely to the composite report itself (for areas definition, see Document Sections).

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrintingLinks;
// ...

private void simpleButton1_Click(object sender, EventArgs e) {
    // Create objects and define event handlers.
    CompositeLink composLink = new CompositeLink(new PrintingSystem());
    composLink.CreateMarginalHeaderArea +=
        new CreateAreaEventHandler(composLink_CreateMarginalHeaderArea);
    PrintableComponentLink pcLink1 = new PrintableComponentLink();
    PrintableComponentLink pcLink2 = new PrintableComponentLink();
    Link linkMainReport = new Link();
    linkMainReport.CreateDetailArea +=
        new CreateAreaEventHandler(linkMainReport_CreateDetailArea);
    Link linkGrid1Report = new Link();
    linkGrid1Report.CreateDetailArea +=
        new CreateAreaEventHandler(linkGrid1Report_CreateDetailArea);
    Link linkGrid2Report = new Link();
    linkGrid2Report.CreateDetailArea +=
        new CreateAreaEventHandler(linkGrid2Report_CreateDetailArea);

    // Assign the controls to the printing links.
    pcLink1.Component = this.gridControl1;
    pcLink2.Component = this.gridControl2;

    // Populate the collection of links in the composite link.
    // The order of operations corresponds to the document structure.
    composLink.Links.Add(linkGrid1Report);
    composLink.Links.Add(pcLink1);
    composLink.Links.Add(linkMainReport);
    composLink.Links.Add(linkGrid2Report);
    composLink.Links.Add(pcLink2);

    // Create the report and show the preview window.
    composLink.ShowPreviewDialog();
}

// Inserts a PageInfoBrick into the top margin to display the time.
void composLink_CreateMarginalHeaderArea(object sender, CreateAreaEventArgs e) {
    e.Graph.DrawPageInfo(PageInfo.DateTime, "{0:hhhh:mmmm:ssss}", Color.Black,
        new RectangleF(0, 0, 200, 50), BorderSide.None);
}

// Creates a text header for the first grid.
void linkGrid1Report_CreateDetailArea(object sender, CreateAreaEventArgs e) {
    TextBrick tb = new TextBrick();
    tb.Text = "Northwind Traders";
    tb.Font = new Font("Arial", 15);
    tb.Rect = new RectangleF(0, 0, 300, 25);
    tb.BorderWidth = 0;
    tb.BackColor = Color.Transparent;
    tb.HorzAlignment = DevExpress.Utils.HorzAlignment.Near;
    e.Graph.DrawBrick(tb);
}

// Creates an interval between the grids and fills it with color.
void linkMainReport_CreateDetailArea(object sender, CreateAreaEventArgs e) {

    TextBrick tb = new TextBrick();
    tb.Rect = new RectangleF(0, 0, e.Graph.ClientPageSize.Width, 50);
    tb.BackColor = Color.Gray;
    e.Graph.DrawBrick(tb);
}

// Creates a text header for the second grid.
void linkGrid2Report_CreateDetailArea(object sender, CreateAreaEventArgs e) {
    TextBrick tb = new TextBrick();
    tb.Text = "Suppliers";
    tb.Font = new Font("Arial", 15);
    tb.Rect = new RectangleF(0, 0, 300, 25);
    tb.BorderWidth = 0;
    tb.BackColor = Color.Transparent;
    tb.HorzAlignment = DevExpress.Utils.HorzAlignment.Near;
    e.Graph.DrawBrick(tb);
}
See Also