Click here to Skip to main content
16,018,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
https://learn.microsoft.com/answers/storage/attachments/275060-untitled.png[^]
"PLEASE OPEN THE IMAGE 1ST"

Good day,

I want to print that data from datagridview using printdocument without using any connection string connect to database.

I am using printdocument to print text, and here's my code.
e.Graphics.DrawString(dtgREPORT.Rows[l].Cells[1].FormattedValue.ToString(), dtgREPORT.Font = new Font("Arial", 10), Brushes.Black, new RectangleF(0, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//stock numbr


What I have tried:

and I tried to create for the image, but it's error
e.Graphics.DrawImage((Image)dtgREPORT.Rows[l].Cells[2].Value, new RectangleF(125, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));

Please open the image.
https://learn.microsoft.com/answers/storage/attachments/275253-untitled.png[^]
Posted
Updated 31-Dec-22 15:27pm
Comments
Graeme_Grant 31-Dec-22 21:30pm    
Please do not repost questions when you are not happy with the answer that you get. Update the original question with more information so others can better understand what you asked.

Original question (yesterday) here: Print all data in datagridview including image using printdocument in c#.[^]
adriancs 1-Jan-23 5:12am    
In my approach, I will encode the images as base64 data, then compose it as HTML doc. Then use webbrowser control or webview2 to print it. Or use Microsoft Edge to convert the HTML as PDF.
JC HoBits 1-Jan-23 5:31am    
adriancs Good day, Have you a code for that? I'm not expert in HTML I hope you can help me.
adriancs 1-Jan-23 5:55am    
Basic printing with webbrowser is easy. but however, u have to be familiar with HTML first. you may refer [here] and [here] for webbrowser printing.
JC HoBits 1-Jan-23 6:22am    
Thank you adriancs, I will try my best.

1 solution

As I am unfamiliar with how to print a Datagrid using ProtDocument, I did a quick google search: c# print datagridview using printdocument - Google[^]and there were lots of solutions - first 3 results:
* C# DataGridView Printing[^]
* How To Print Datagridview In C# - YouTube[^]
* C# Tutorial - How to Print a DataGridView | FoxLearn - YouTube[^]
If none of these are suitable, then look at the others in the search.
 
Share this answer
 
Comments
JC HoBits 31-Dec-22 22:12pm    
Thank you it's appreciate.

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