* Take one datagridview1 control. * Take one printdocument1 * & two buttons named as retrive & print.
Develop code for retriving & bind it to the datagridview in retrive button.
Code for Print_click:
private void print_Click(object sender, EventArgs e) { printDocument1.Print(); }
Then develop code for printdocument1_printpage event:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) {
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); }
Then finally execute the project.It will print the datagrinview content only.
|
| Author: pradeep 16 Apr 2009 | Member Level: Bronze Points : 1 |
If a datagridview has more rows which is not displayed on the current form then whether its get printed or not. I mean if datagridview has more rows which we have to scroll down then its get printed or not.
|