I have a gridview in which I show report data, I wanted to print this data, so I added print functionality. This print functionality does not print entire gridview data, it only prints data which is visible on the screen and skip the data which is under vertical scroll bar.
Below is the print grid view code in c# for WINDOWS APPLICATION.
Below is the print grid view code in c# for WINDOWS APPLICATION.
Code:
private void btnPrint_Click(object sender, EventArgs e) { if (printDialog1.ShowDialog() == DialogResult.OK) { printDocument1.Print(); } } private void btnPrintPreview_Click(object sender, EventArgs e) { printPreviewDialog1.Document = printDocument1; printPreviewDialog1.ShowDialog(); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Bitmap bm = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height); dataGridView1.DrawToBitmap(bm, new Rectangle(0, 0, this.dataGridView1.Width, this.dataGridView1.Height)); e.Graphics.DrawImage(bm, 0, 0); }
Comment