Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How Do i print the Total Grid Columns In single page By rotating the grid into horizontal when printing the page ???

When AM Printing My Grid it displaying in two pages but i want total grid in single page when printing.

code:
C#
public void ShowPrintButtons()
       {
           if (this.dgvODReport.RowCount >= 1)
           {
               btnPrint.Visible = true;
               btnPrintPreview.Visible = true;
           }
           else
           {
               btnPrint.Visible = false;
               btnPrintPreview.Visible = false;
           }
       }
       private bool SetupThePrinting()
       {
           PrintDialog MyPrintDialog = new PrintDialog();
           MyPrintDialog.AllowCurrentPage = false;
           MyPrintDialog.AllowPrintToFile = false;
           MyPrintDialog.AllowSelection = false;
           MyPrintDialog.AllowSomePages = false;
           MyPrintDialog.PrintToFile = false;
           MyPrintDialog.ShowHelp = false;
           MyPrintDialog.ShowNetwork = false;



           if (MyPrintDialog.ShowDialog() != DialogResult.OK)
               return false;

           MyPrintDocument.DocumentName = "OD Report";
           MyPrintDocument.PrinterSettings = MyPrintDialog.PrinterSettings;
           MyPrintDocument.DefaultPageSettings = MyPrintDialog.PrinterSettings.DefaultPageSettings;
           MyPrintDocument.DefaultPageSettings.Margins = new Margins();

           PaperSize paperSize = new PaperSize("Super B", 1100, 820);
           paperSize.RawKind = (int)PaperKind.Custom;
          // MyPrintDocument.DefaultPageSettings.PaperSize = paperSize;
           MyPrintDocument.DefaultPageSettings.Landscape = true;
           MyPrintDocument.DefaultPageSettings.Margins = new Margins(0, 00, 0, 0);


           if (MessageBox.Show("Do you want the report to be centered on the page", "InvoiceManager - Center on Page", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
               MyDataGridViewPrinter = new DataGridViewPrinter(dgvODReport, MyPrintDocument, true, true," " + dtptodaydate.Value.ToString("MMMM") + "", new Font("Arial", 15, FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);

           else
               MyDataGridViewPrinter = new DataGridViewPrinter(dgvODReport, MyPrintDocument, true, true,"", "" + dtptodaydate.Value.ToString("MMMM") + "", new Font("Arial", 15, FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);

           return true;
       }

       private void btnPrint_Click(object sender, EventArgs e)
       {
           if (SetupThePrinting())
               MyPrintDocument.Print();
       }

       private void btnPrintPreview_Click(object sender, EventArgs e)
       {

           if (SetupThePrinting())
           {
               PrintPreviewDialog MyPrintPreviewDialog = new PrintPreviewDialog();
               MyPrintPreviewDialog.Document = MyPrintDocument;
               MyPrintPreviewDialog.ShowDialog();

           }

       }

       private void MyPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
       {


            bool more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics);
            if (more == true)

                e.HasMorePages = true;

       }
Posted
Updated 1-Nov-14 0:22am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900