Printing of DataGridView in Winform C#

I am trying to Printing Datagridview by making bitmap image , Its working nicely but it printing only in 1 page to print .

Here is DataGirdView Image :

enter image description here

Print Preview Image :

enter image description here

Here in print-Preview not having total rows to the last as of DataGridView row and only having 1 page

Code of Printing :

 private void Btn_Print_Click(object sender, EventArgs e) { int height = DGV.Height; DGV.Height = DGV.RowCount * DGV.RowTemplate.Height * 2; bmp = new Bitmap(DGV.Width, DGV.Height); DGV.DrawToBitmap(bmp, new Rectangle(0, 0, DGV.Width, DGV.Height)); DGV.Height = height; printPreviewDialog1.ShowDialog(); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(bmp, 0, 0); } 

Why not printing data in more than 1 page ? Is there any wrong in code ? Please give suggestion

Thank you .

1 Answer

It's not the easiest thing to print multiple pages from a DataGridView so I recommend you to use one of the existing code samples. Here's couple good ones which are easy to use and can print multiple pages:

Some more examples are available from this SO question:

Best way to print a datagridview with all rows and all columns?

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like