Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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();
            printDialog.ShowDialog();
 
            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)
            {
                this.printDocument1.Print();
            }
        }
        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
 
meenakshi
Posted 26-Jul-12 0:24am
Edited 26-Jul-12 0:38am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
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.
 
Thanks
-Amit Gajjar
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 26 Jul 2012
Copyright © CodeProject, 1999-2014
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