Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
As the title says, I wish to print out a datagridview with the same exact layout and format(bold,font sizes etc) that it currently shows, I also want it to separate every specific number of rows from every page that it prints.

Assume that the datagridview is unrelated to any other datasource and it basically has generic data but with a certain layout, How do I print this? I've tried and experimented on various codes from google but to no avail, everything seems to take information from datasets / datatables etc.

This is really an issue for me right now, as not being able to print out the report renders the aopplication useless, and I can't seem to find a solid way of just showing this information properly on a hard copy.

Using basic Print Document commands that I've found have also not worked, for example, http://csharp.net-informations.com/datagridview/csharp-datagridview-printing.htm

left out a part of my second column and the entire 3rd column and several rows ( perhaps it wasn't fit to page?) Any help on how to accomplish this would be greatly appreciated, whether it be somehow moving it to a reportviewer or transfering its data to datatables or anything that I must do to basically print out the datagridview exactly as its shown, Thank you.
Posted
Comments
Sergey Alexandrovich Kryukov 20-Sep-14 14:37pm    
This is no such thing as "Print Document commands". There is the class PrintDocument; and this is what you have to use. If you used it poorly, you did not give us relevant information; so how one can help you. Just use this class and pay attention for all the detail.
—SA

I want to argue on the following statement: the problem does not have good solution at the level of abstraction based on the information you provided. Such solution could be either universal but produce ugly look in many cases, or it would look good enough if based on some assuptions, but would not fit all cases.

At the same time, it's possible that the problem is well solvable at the level of your application; you would only need to make assumptions instead of trying to make the solution universal. But you did not provide enough information on your application, so you have to deal with it by yourself. Please see my comment to the question.

One universal solution is this: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.printing.printform.aspx[^].

Another one is this: Form Print Control[^].

You can also use the ideas and do something close to your needs if you read the article.

So, why the universal solution is not good enough? This is simple. Because paper is not screen and not interactive. In a window form, you always have DataGridView scrolling, and can add form resize and zoom and/or pan. None of that would work for paper. The data, elementary, may not fit.

Generally, printing from UI controls is not the best idea. More advanced and regular idea is to print using the data source.

—SA
 
Share this answer
 
v2
Convert it into HTML page with CSS (colouring) with your table and print it by using WebBrowser control. WebBrowser has a print function.

To split the data into multiple pages, just measure the total lines that a page can allocate, then manually separate the table into multiple tables.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900