Click here to Skip to main content
11,929,505 members (55,834 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Application
I have datagridview which is displaying teh data from database .
I want take a print of that complete data .
My code is :
private void button3_Click(object sender, EventArgs e)
            PrintDialog printDialog = new PrintDialog();
            printDialog1.AllowSomePages = true;
            // Show the help button.  
            printDialog1.ShowHelp = true;

            printDialog1.Document = docToPrint;
            DialogResult result = printDialog1.ShowDialog();
            // If the result is OK then print the document.       
            if (result == DialogResult.OK)
        private void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            string text = "In document_PrintPage method.";
            System.Drawing.Font printFont = new System.Drawing.Font
                ("Arial", 35, System.Drawing.FontStyle.Regular);
            e.Graphics.DrawString(text, printFont,
            System.Drawing.Brushes.Black, 10, 10);
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            DataGridViewCheckBoxCell chkcell = dataGridView1[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
            if (chkcell != null)
                columnsToPrint[dataGridView1.CurrentRow.Index] = Convert.ToBoolean(chkcell.EditedFormattedValue);
            if (dataGridView1.RowCount > 5)
                //MessageBox.Show("There are a maximum of 31 days in a month buddy");
                dataGridView1.AllowUserToAddRows = false;
        private void printDocument1_PrintPage(object sender, 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);
This code is working but it will display only the screenshot type means data that is visible at current size.....not the whole one.

pls reply

Posted 26-Jul-12 0:24am
Edited 26-Jul-12 0:38am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


You can generate HTML report out from your Data.

Please Refer The HTML Report Engine[^]

Or you can manually create HTML table to generate your report out from your DataSource.

-Amit Gajjar

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 26 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100