I am having an issue printing listView items.
the problem I think is at private void PrintPageDetail(PrintPageEventArgs e)
So this is what's going on:
it prints whatever fits on one page over and over. (There is more data than what is printed) although the page footer and header print OK with the right page numbers. and I am having hard time getting it to clear the memory everytime to map the new data on the next page.
the print preview and printing won't stop, unless I hit cancel (probably due to the indefinite loop "return;").
Thank you for any help
private void PrintDocument(object sender, PrintPageEventArgs e)
{
// Use inches for all measurements.
e.Graphics.PageUnit = GraphicsUnit.Inch;
PrintPageHeader(e);
PrintPageDetail(e);
PrintPageFooter(e);
}
// Print the page header/footer/details.
private void PrintPageHeader(PrintPageEventArgs e)
{
e.Graphics.DrawString("Factors List Report",
_headerFont, _reportBrush, 3.0F, 0.75F);
e.Graphics.DrawLine(_reportPen, 0.5F, 1.15F, 7.5F, 1.15F);
}
private void PrintPageFooter(PrintPageEventArgs e)
{
e.Graphics.DrawLine(_reportPen, 1.0F, 10.0F, 7.5F, 10.0F);
e.Graphics.DrawString("Printed on " + DateTime.Now.ToLongDateString(),
_footerFont, _reportBrush, 1F, 10.2F);
_pageNumber++;
e.Graphics.DrawString(string.Format("Page: {0}", _pageNumber),
_footerFont, _reportBrush, 7F, 10.2F);
}
private void PrintPageDetail(PrintPageEventArgs e)
{
// Create variables to hold position on page.
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
float i = 1.25F;
e.HasMorePages = false;
foreach (string printerLine in _factorsView)
{
e.Graphics.DrawString(printerLine, _detailFont, _reportBrush, 1.0F, i);
if (i >= 9.75)
{
i += 1.25F;
e.HasMorePages = true;
return;
}
else
i += .25F;
}
}
}