I'm creating a print preview function in a system that I'm developing which will preview the datagridview that I want to print. I used ooopsoft's codes as reference and it works fine except for a slight problem.
Problem:
In the you can see that the dgv row with serial number 1 is missing. It appears the header has overwritten the 1st row. I have tried a myriad of ways to solve it, but I still can't find the solution. I tried exiting the print preview dialog and opening it again, but this is the result I got. I think I'm missing a line of code, but I can't figure out what. Please help.
The original code is a nice start but has a couple of bugs and inefficiecies:
newpage
flag to print the header or the first row when there is a new page. Obviously you really want it to do bothsingle
andRectangleF
mRow
andnewpage
either in the button click orBeginPrint
event.I added a few comments as well as coloring the header row and demonstrating how to implement things like a
RowPrePaint
rule.Note that there is an
Id
column set to invisible in the DGV, theColor
column is centered andPrice
is left justified - these are all settings picked up from the control. Also note that the text is moved away from the gridlines just a bit.The last bullet point above, You will also want to reset
mRow
andnewpage
either in the button click orBeginPrint
event. means this:After you preview the
mRow
variable will indicate that all the rows have been printed. If the user clicks Print or goes back for another Preview, nothing will print. This code also resets the first page to show and the initial Zoom.