)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to print the contents of the Grid to fit the width of the page in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 27, 2016 |
Last Revised Date: December 16, 2019

Printing

To print the contents of the grid to fit into the width of the page, it can be done by using GridPrintDocument without any page breaks. GridPrintToFitDocument can be used to print the document properly which is derived from the GridPrintDocument. To utilize this class, you need to add the GridHelperClasses.Windows.dll as reference.

C#

private void button3_Click(object sender, EventArgs e)
{
    if (this.gridControl1 != null)
    {
        try
        {
            //uses the default printer
            GridPrintToFitDocument pd = new GridPrintToFitDocument(this.gridControl1, true);
            PrintPreviewDialog dlg = new PrintPreviewDialog();
            dlg.Document = pd;
            pd.DefaultPageSettings.Landscape = true;
            dlg.ShowDialog();
        }
        catch (Exception ex)
        {
            MessageBox.Show("An error occurred attempting to preview the grid - " + ex.Message);
        }
    }
    if (this.gridControl1 != null)
    {
        try
        {
            GridPrintToFitDocument pd = new GridPrintToFitDocument(this.gridControl1, true);
            PrintDialog dlg = new PrintDialog();
            dlg.Document = pd;
            pd.DefaultPageSettings.Landscape = true;
            if (dlg.ShowDialog() == DialogResult.OK)
                pd.Print();
        }
        catch (Exception ex)
        {
            MessageBox.Show("An error occurred attempting to print the grid - " + ex.Message);
        }
    }
}

 

VB

Private Sub button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button3.Click
 If Me.gridControl1 IsNot Nothing Then
  Try
   'uses the default printer
   Dim pd As New GridPrintToFitDocument(Me.gridControl1, True)
   Dim dlg As New PrintPreviewDialog()
   dlg.Document = pd
   pd.DefaultPageSettings.Landscape = True
   dlg.ShowDialog()
  Catch ex As Exception
   MessageBox.Show("An error occurred attempting to preview the grid - " & ex.Message)
  End Try
 End If
 If Me.gridControl1 IsNot Nothing Then
  Try
   Dim pd As New GridPrintToFitDocument(Me.gridControl1, True)
   Dim dlg As New PrintDialog()
   dlg.Document = pd
   pd.DefaultPageSettings.Landscape = True
   If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    pd.Print()
   End If
  Catch ex As Exception
   MessageBox.Show("An error occurred attempting to print the grid - " & ex.Message)
  End Try
 End If
End Sub

 

 

Show the print preview of the grid data

Print to fit the page of grid

Samples:

C#: Print page

VB: Print page

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
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
Live Chat Icon