Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing a .NET DataGridView

I am fairly new to .NET and C#, but I have a DataGridView that I would like to print. What would be the best way to go about doing so?

like image 446
Tina Orooji Avatar asked Feb 18 '09 14:02

Tina Orooji


People also ask

What is Dgvprinter C#?

This class includes codes to print Bill from data grid view in C# windows form application.


2 Answers

Add a DataGridView, a PrintDocuemnt, and a Button then:

button click events {
    printDocument1.Print();
}

printDocument1_PrintPage events {
    Bitmap bm = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height);
    this.dataGridView1.DrawToBitmap(bm, new Rectangle(0, 0, this.dataGridView1.Width, this.dataGridView1.Height));
    e.Graphics.DrawImage(bm, 0, 0);
}

That's all your data printing.

like image 121
3 revs, 3 users 54%mehmet Avatar answered Sep 20 '22 22:09

3 revs, 3 users 54%mehmet


There are projects on CodeProject that have done some work printing DataGridViews.

like image 29
Bob Avatar answered Sep 18 '22 22:09

Bob