Click here to Skip to main content
15,615,469 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

Updated 25-Jul-12 23:38pm


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
Share this answer

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