if the pages is more than 1 and i press a button the print preview don't stop generating print preview it will only stop if press the cancel button, then it will display the table with more than 1 pages but the data inside the tables is just the same. how can i solve this print preview problem that keeps generating print preview and the repetition of data?? thank you in advance :D
private void button3_Click(object sender, EventArgs e)
{ printPreviewDialog1.ShowDialog(); }
here is the code in my PrintDocument:
else if (radioButton2.Checked)
{
while (i < dataGridView1.Rows.Count)
{
if (height > e.MarginBounds.Height)
{
height = 130;
width = 100;
e.HasMorePages = true;
return; }
else
{ e.HasMorePages = false; }
e.Graphics.DrawRectangle(Pens.Black, 100, 0,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height);
e.Graphics.FillRectangle(Brushes.LightGray, new Rectangle
(100, 0, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawString(dataGridView1.Columns[0].HeaderText,
dataGridView1.Font, Brushes.Black, new RectangleF(100, 0,
dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);
height += dataGridView1.Rows[i].Height;
e.Graphics.DrawRectangle(Pens.Black, 100, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new RectangleF(100, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);
width += dataGridView1.Columns[0].Width;
i++;
}
}