Skip to main content
A newer version of this page is available. .

Lesson 6 - Insert Two Rows

  • 3 minutes to read

The link created in this lesson generates a document that contains two rows. The first row contains a check box brick in an unchecked state, and an empty brick. The second row is inserted to display the check box in the checked state.

Tip

A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e161/xtraprinting-getting-started.

To insert two rows into the content of a printing link, do the following.

  1. To create a new printing link, declare a new class (Lesson6) derived from the Lesson5 class defined in the previous lesson. The new class overrides the CreateRow and CreateDetail methods to create two new bricks: check box and empty brick.

    using System.Drawing;
    using System.Windows.Forms;
    using DevExpress.XtraPrinting;
    // ...
    
    public class Lesson6 : Lesson5 {
        public Lesson6(PrintingSystem ps) : base(ps) {}
    
        protected override void CreateDetail(BrickGraphics graph) {
            // Center the text string.
            graph.StringFormat = graph.StringFormat.ChangeLineAlignment(StringAlignment.Center);
    
            // Add an unchecked check box brick with all borders displayed
            // to a specific location using the Light Sky Blue background color.
            graph.DrawCheckBox(new Rectangle(150, 0, 50, 50), 
               BorderSide.All, Color.LightSkyBlue, false);
    
            // Add an empty rectangle with all borders displayed
            // to a specific location using the Light Lavender background color.
            graph.DrawRect(new Rectangle(200, 0, 50, 50), 
                BorderSide.All, Color.Lavender, graph.BorderColor);
    
            base.CreateDetail(graph);
        }
    
        protected override void CreateRow(BrickGraphics graph) {
            base.CreateRow(graph);
    
            // Add a checked check box brick with all borders displayed
            // to a specific location using the Light Sky Blue background color.
            graph.DrawCheckBox(new Rectangle(150, top, 50, 50), 
                BorderSide.All, Color.LightSkyBlue, true);
        }
    }
    
  2. Next, modify the main form’s Load event handler to pass the Printing System of the Document Viewer to the new link.

    using System;
    using System.Windows.Forms;
    using DevExpress.XtraPrinting;
    // ...
    
    private void Form1_Load(object sender, System.EventArgs e) {
        Lesson6 lesson = new Lesson6(printingSystem1);
    }
    

Launch the application and view the result.

document-viewer-ribbon-link-document-result-insert-two-rows

See Also