To add headers derive a class from the GridPrintDocument class. Then in the OnPrintPage method of that class you can use the e.graphics.DrawString method to create the header lines. I use an arraylist of the header lines that I pass to the derived Print class via an overloaded constructor.
You will need to scale the grid (the column widths) to the page width which you can retrieve from an instance of your class and it’s (printer) Bounds and Margins properties. For example assume printDoc is th instance variable:
pageWidth = printDoc.DefaultPageSettings.Bounds.Right – (printDoc.DefaultPageSettings.Margins.Right + printDoc.DefaultPageSettings.Margins.Left)
Create an instance of your grid with all the columns set to FittedWidth then adjust all the widths by a factor that fits the page. If the columns’ FittedWidths are too wide, be sure to set the columns to allow word wrapping. Instead of multiplying all column widths by a common factor you may want to set a limit on columns that are extremely wide.
You could also reduce the font size of your grid instance to make it fit the page to avoid the word wrapping, but if you want the printing to look like a report scaling to the page width would still be desirable.
Imported from legacy forums. Posted by Kareem (had 506 views)