We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to print two or more grids on the same page in WinForms GridControl?

Platform: WinForms |
Control: GridControl


You can print two or more grids by customizing the page layout, deriving the GridPrintDocument class and overriding its OnPrintPage method. In the override, you can draw the grids anywhere on the layout.

In the following code example, two grids are drawn on a same page by defining the particular height and weight for each grid.



public class MyGridPrintDocument : GridPrintDocument
 private GridControlBase grid1;
 private GridControlBase grid2;
 public MyGridPrintDocument(GridControlBase grid1, GridControlBase grid2, bool printPreview) : base(grid1, printPreview)
  this.grid1 = grid1;
  this.grid2 = grid2;
 protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs ev)
  //Do not call baseclass...
  //Set where you want the grid displayed...
  int width = grid1.Model.ColWidths.GetTotal(0, grid1.Model.ColCount);
  int height = grid1.Model.RowHeights.GetTotal(0, grid1.Model.RowCount);
  Rectangle topGridRect = new Rectangle(ev.MarginBounds.Left, ev.MarginBounds.Top, width, height);
  grid1.DrawGrid(ev.Graphics, topGridRect, false);
  ev.Graphics.DrawRectangle(Pens.Black, topGridRect);
  //Set where you want the second grid displayed...
  width = grid2.Model.ColWidths.GetTotal(0, grid2.Model.ColCount);
  height = grid2.Model.RowHeights.GetTotal(0, grid2.Model.RowCount);
  Rectangle botGridRect = new Rectangle(ev.MarginBounds.Left, ev.PageBounds.Height/2, width, height);
  grid2.DrawGrid(ev.Graphics, botGridRect, false);
  ev.Graphics.DrawRectangle(Pens.Black, botGridRect);



Public Class MyGridPrintDocument
        Inherits GridPrintDocument
        Private grid1 As GridControlBase
        Private grid2 As GridControlBase
        Public Sub New(ByVal grid1 As GridControlBase, ByVal grid2 As GridControlBase, ByVal printPreview As Boolean)
            MyBase.New(grid1, printPreview)
            Me.grid1 = grid1
            Me.grid2 = grid2
        End Sub
        Protected Overrides Sub OnPrintPage(ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
            'Do not call baseclass...
            'Set where you want the grid displayed...
            Dim width As Integer = grid1.Model.ColWidths.GetTotal(0, grid1.Model.ColCount)
            Dim height As Integer = grid1.Model.RowHeights.GetTotal(0, grid1.Model.RowCount)
            Dim topGridRect As New Rectangle(ev.MarginBounds.Left, ev.MarginBounds.Top, width, height)
            grid1.DrawGrid(ev.Graphics, topGridRect, False)
            ev.Graphics.DrawRectangle(Pens.Black, topGridRect)
            'Set where you want the second grid displayed...
            width = grid2.Model.ColWidths.GetTotal(0, grid2.Model.ColCount)
            height = grid2.Model.RowHeights.GetTotal(0, grid2.Model.RowCount)
            Dim botGridRect As New Rectangle(ev.MarginBounds.Left, ev.PageBounds.Height \ 2, width, height)
            grid2.DrawGrid(ev.Graphics, botGridRect, False)
            ev.Graphics.DrawRectangle(Pens.Black, botGridRect)
        End Sub
    End Class




C#: Print Multiple Grid CS

VB: Print Multiple Grid VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile