Subscribe to Subscribers

Resources » Code Snippets » DataGridView

Printing Datagridview content in windows aplication using C#.net.


Posted Date:     Category: DataGridView    
Author: Member Level: Gold    Points: 4



* 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.





Did you like this resource? Share it with your friends and show your love!


Responses to "Printing Datagridview content in windows aplication using C#.net."
Author: pradeep    16 Apr 2009Member 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.


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: BINDING (System.Collections.Generic.List) TO GRIDVIEW
    Previous Resource: Retrive value from datagrid
    Return to Resources
    Post New Resource
    Category: DataGridView


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Printing Datagridview content  .  

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2013 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.