How to print entire gridview data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samnine
    New Member
    • Mar 2013
    • 7

    How to print entire gridview data

    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.

    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);
            }
  • M1kkelZU
    New Member
    • Feb 2013
    • 80

    #2
    have a look at this:


    I found it usefull for my use of the datagridview and printing

    Comment

    • samnine
      New Member
      • Mar 2013
      • 7

      #3
      M1kkelZU,
      Thanks for ur help, but the link provided by you didn't work for me. However, I found much SIMPLER way on code project to print grid view. It is very easy and simple to use, it just need to add a DLL or class to ur code and paste code snippet for button click to print the gridview...

      Below is the link, it might be helpful for other users..

      Comment

      • M1kkelZU
        New Member
        • Feb 2013
        • 80

        #4
        Ah yeah I did see that one pop up on my initial search, I just didn't read that fully. Still as long as your problem is solved there can be no harm :)

        Comment

        Working...