How to print only the specific pages of the grid in WinForms GridControl?
Printing
To customize the specific pages for printing in WinForms Grid Control, 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.
C#
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..."); }
VB
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.
Samples:
C#: Somepages print-C#
VB: Somepages print-VB
Reference link: https://help.syncfusion.com/windowsforms/grid-control/printing
Conclusion
I hope you enjoyed learning about how to print only the specific pages of the grid in WinForms Grid Control.
You can refer to our WinForms Grid Control’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Grid Control documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Grid Control and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!