int y = 365;
for (int i = NumberofItemsperpagesofar; i < dataGridView1.Rows.Count; i++)
{
NumberofItemsperpage++;
if (NumberofItemsperpage <= 10)
{
NumberofItemsperpagesofar++;
if (NumberofItemsperpagesofar <= dataGridView1.Rows.Count)
{
Pen m = new Pen(Brushes.Black, 2.5f);
try
{
if (dataGridView1.Rows[i].Cells[0].Value == dataGridView1.Rows[i].Cells[0].Value)
{
e.Graphics.DrawString(dataGridView1.Rows[0].Cells[0].Value.ToString(), new Font("Times New Roman", 18, FontStyle.Bold), Brushes.Black, new Point(10, 355));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].Value.ToString(), new Font("Calibri", 15, FontStyle.Bold), Brushes.Black, new Point(7, y+ 17));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[4].Value.ToString(), new Font("Calibri", 16, FontStyle.Bold), Brushes.Black, new Point(310, y +17));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[3].Value.ToString(), new Font("Calibri", 16, FontStyle.Bold), Brushes.Black, new Point(545, y +17));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[2].Value.ToString(), new Font("Calibri", 16, FontStyle.Bold), Brushes.Black, new Point(690, y +17));
}
else if (dataGridView1.Rows[i].Cells[0].Value != dataGridView1.Rows[i].Cells[0].Value)
{
e.Graphics.DrawString(dataGridView1.Rows[0].Cells[0].Value.ToString(), new Font("Times New Roman", 18, FontStyle.Bold), Brushes.Black, new Point(10, y+25));
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
y += 30;
}
else
{
e.HasMorePages = false;
}
}
else
{
NumberofItemsperpage = 0;
e.HasMorePages = true; return;
}
}
What I have tried:
i want to print cell[0] value one time and all other cells every time and when cell[0] value change then print again please help me to solve this problem