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 only the specific pages of the grid in WinForms GridControl?

Platform: WinForms |
Control: GridControl
Tags: printing


To customize the specific pages for printing, you can use the PrintPage event. This event can be triggered for each page during printing. You can also use BeginPrint event. This event is triggered once printing is performed.

The default value of the PrintRange is All. For printing the specific pages, it should be changed to PrintRange.SomePages through BeginPrint event.

 In the following code example, the first and second pages are selected for printing.


Syncfusion.GridHelperClasses.GridPrintDocumentAdv pd = new Syncfusion.GridHelperClasses.GridPrintDocumentAdv(this.gridControl1);
//Triggers the BeginPrint event
pd.BeginPrint += new System.Drawing.Printing.PrintEventHandler(pd_BeginPrint);
//Triggers the PrintPage event
pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);
//Handles the BeginPrint event
private void pd_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
  ((GridPrintDocumentAdv)sender).PrinterSettings.PrintRange = PrintRange.SomePages;
  //Prints 1st and 2nd page
  ((GridPrintDocumentAdv)sender).PrinterSettings.FromPage = 1;
  ((GridPrintDocumentAdv)sender).PrinterSettings.ToPage = 2;
//Handles the PrintPage event
private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  //Customizes your code here
  Console.WriteLine("The page is printing...");



Private pd As New Syncfusion.GridHelperClasses.GridPrintDocumentAdv(Me.gridControl1)
'Triggers the BeginPrint event
Private pd.BeginPrint += New System.Drawing.Printing.PrintEventHandler(AddressOf pd_BeginPrint)
'Triggers the PrintPage event
Private pd.PrintPage += New System.Drawing.Printing.PrintPageEventHandler(AddressOf pd_PrintPage)
'Handles the BeginPrint event
Private Sub pd_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
  CType(sender, GridPrintDocumentAdv).PrinterSettings.PrintRange = PrintRange.SomePages
  'Prints 1st and 2nd page
  CType(sender, GridPrintDocumentAdv).PrinterSettings.FromPage = 1
  CType(sender, GridPrintDocumentAdv).PrinterSettings.ToPage = 2
End Sub
'Handles the PrintPage event
Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
  'Customizes your code here
  Console.WriteLine("The page is printing...")
End Sub



In the above example, particular pages are printed when you press print button. The Range of pages can be given by using the FromPage and ToPage properties of the PrinterSettings.



C#: Somepages print-C#
VB: Somepages print-VB

Reference link: https://help.syncfusion.com/windowsforms/grid-control/printing

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