Click here to Skip to main content
15,898,984 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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);
                        // e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].Value.ToString(), new Font("Microsoft Sans Serif", 16, FontStyle.Regular), Brushes.Black, new Point(15, y - 4));
                        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.DrawLine(q, new Point(0, y + 24), new Point(1000, y + 24));
                                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
Posted
Updated 27-Dec-16 18:55pm
v2
Comments
ZurdoDev 27-Dec-16 8:14am    
Then write code to do what you want. Where are you stuck?
Michael_Davies 27-Dec-16 9:43am    
Your code does not make sense, you test the value of cell[0] to be equal to itself, it always will be. You then test cell[0] not equal to itself on the else which, as it is an else to the opposite condition is not required, plus it will never execute as cell[0] is always equal to cell[0].

This code looks like part of a print routine, normally there would be other code that would call this routine, in that code you need to store the value of cell[0] and compare against that value, when there is a difference, cell[0] changed, then save the new cell[0] value and execute your print.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900