Skip to content

How to print multi datagridview in a single page in c#

Pavithra L

Pavithra L

Asked Oct 1, 2015, 10:26 PM EDT1 answer
Share
LinkedInX
Hai,
 
Anybody can help this problem , Its too urgent to finish it quickly. So kindly reply this question.
 
My project is C# windows application. Here I want to print two datagridview in a single page not in next page. So, here am using tabcontrol option for separate datagridview. I can select this tabcontrol one by one , while I can select two tabIndex value and also print one by one in next next pages . but I want this each tabcontrol value in single  printed page . How can I print like this in my project, Please kindly suggest any idea to solve this Issue.
 
Am waiting for the reply. Thanks in advance. 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Partha Sarathi
    0
    Hi.
    C#
     Try this i hope this will help you
    
     private void button1_Click(object sender, EventArgs e)
        {
          printDocument1.DefaultPageSettings.Landscape = true;
          printDocument1.DefaultPageSettings.Margins = new Margins(50, 50, 50, 50);
          printDocument1.OriginAtMargins = true;
          printDocument1.Print();
        }
        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
          int w = System.Math.Max(dataGridView1.Width, dataGridView2.Width);
          int h = dataGridView1.Height + dataGridView1.Height;
          Bitmap bmp = new Bitmap(w,h);
          Rectangle r = new Rectangle(0,0,dataGridView1.Width, dataGridView1.Height);
          dataGridView1.DrawToBitmap(bmp,r);
          r.Y = dataGridView1.Height;
          r.Width = dataGridView2.Width;
          r.Height = dataGridView2.Height;
          dataGridView2.DrawToBitmap(bmp, r);
          e.Graphics.DrawImage(bmp, e.MarginBounds);
        }
      }
    }
    0