How to print data grid view values at multiple pages
I am creating windows application using c# 2010 here I am using data grid view for reporting purpose, in my data grid view having above 100 rows, I want print multiple page my data grid view values I am write a code on printDocument1_PrintPage event handler, but data's cannot shown on second page at print timethis is my code any one give me just ideas
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
try
{
Graphics graphic = e.Graphics;
e.PageSettings.PaperSize = new PaperSize("A4", 850, 1100);
float pageWidth = e.PageSettings.PrintableArea.Width;
float pageHeight = e.PageSettings.PrintableArea.Height;
Font font = new Font("Times New Roman", 10, FontStyle.Bold);
float fontHeight = font.GetHeight();
int startX = 40;
int startY = 30;
int offsetY = 40;
System.Drawing.Font fntString = new Font("Times New Roman", 10, FontStyle.Bold);
System.Drawing.Font fnthead = new Font("Arial", 20, FontStyle.Bold);
while (s < gvpurchase.Rows.Count)
{
if (s % 2 == 0)
{
for (; s <= 100; s++)
{
offsetY += (int)fontHeight;
if (offsetY >= pageHeight)
{
e.HasMorePages = true;
offsetY = 0;
return;
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[2].Value.ToString(), fntString, Brushes.Black, 70, (s * 93) + 20);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[3].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 20);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[4].Value.ToString(), fntString, Brushes.Black, 70, (s * 93) + 40);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[5].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 40);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[6].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 60);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[7].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 80);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[8].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 100);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[9].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 120);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[10].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 140);
}
else
{
e.HasMorePages = false;
}
}
}
else
{
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[2].Value.ToString(), fntString, Brushes.Black, 370, ((s - 1) * 93) + 20);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[3].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 20);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[4].Value.ToString(), fntString, Brushes.Black, 370, ((s - 1) * 93) + 40);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[5].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 40);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[6].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 60);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[7].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 80);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[8].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 100);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[9].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 120);
e.Graphics.DrawString(gvpurchase.Rows[s].Cells[10].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 140);
}
}
s++;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
any give me ideas.