Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to have an outcome like this..

Title
Subtitle
label1.Text
label2.Text
label3.Text
etc..
then
datagridview

is it possible? and what property of DGVPrinter should I call to solve this problem?

What I have tried:

This is my code in the print button.

private void btnprint_Click(object sender, EventArgs e)
{
DGVPrinter printer = new DGVPrinter();
printer.Title = "Individual Treatment Record";
printer.SubTitle = "Name:"+" " + (lblname.Text);
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Near;
printer.Footer = "";
printer.FooterSpacing = 15;
printer.PrintDataGridView(dataGridView1);

}
Posted
Updated 13-Sep-20 21:21pm

It's possible, but it means you can't use a DGVPRinter instance - whatever that is, probably a Github class:DGVPrinter[^]

When you want to print a bunch of information together, you use the PrintDocument Class (System.Drawing.Printing) | Microsoft Docs[^] to layout exactly what you want on the page, where you want it, and including all the information exactly as you want to display it - that's almost certainly what your DGVPrint class does internally at the moment.

That means that you decide where your "header text" goes, in what font, and then print the content of your DGV yourself as well.
 
Share this answer
 
Comments
BillWoodruff 14-Sep-20 3:15am    
fyi: the GitHub project uses the MS DataGridView, and extends it.
Why haven't you done some research: [^] ?

On this Google page I see a link to a CodeProject article on an extended DataGridView Printer, a link to a specific MSDN question about how to add a text field, a link to the GitHub DGV prinnterproject, and more.

Consider designing your DataGridView with a top row where your meta-data can be placed: if the DataGridView supports this, that row could be hidden at run-time, then, at print time have its fields filled in and made visible. The MS DataGridView suooprts headers and footers: investigatee how to us them.

Make some effort !
 
Share this answer
 

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