1st step works perfect but 2nd step loop doesn't stop
<p><strong>1st step:</strong></p>

<pre><code>private void SetInvoiceData(Graphics g, System.Drawing.Printing.PrintPageEventArgs e)
 {
   // Set Invoice Table:
   string FieldValue = "";
   int CurrentRecord = 0;
   int RecordsPerPage = 20; // twenty items in a page
   decimal Amount = 0;
   bool StopReading = false;

            // Set Table Head:
            int xCustomerName = leftMargin;
            CurrentY = CurrentY + InvoiceFontHeight;

            g.DrawString("Customer Name", InvoiceFont, BlueBrush, xCustomerName, CurrentY);
            int xNumber = xCustomerName+ (int)g.MeasureString("Customer Name", InvoiceFont).Width + 4;

            g.DrawString("Number", InvoiceFont, BlueBrush, xNumber, CurrentY);
            int xAddress = xNumber + (int)g.MeasureString("Number", InvoiceFont).Width + 72;

            g.DrawString("Address", InvoiceFont, BlueBrush, xAddress, CurrentY);
            int xSpecialization = xAddress + (int)g.MeasureString("Address", InvoiceFont).Width + 4;

            g.DrawString("Specialization", InvoiceFont, BlueBrush, xSpecialization, CurrentY);
            //int xSpecialization = xAddress + (int)g.MeasureString("Specialization", InvoiceFont).Width + 4;

            //g.DrawString("Discount", InvoiceFont, BlueBrush, xSpecialization, CurrentY);

            AmountPosition = xSpecialization + (int)g.MeasureString("Specialization", InvoiceFont).Width + 4;
           //g.DrawString("Extended Price", InvoiceFont, BlueBrush, AmountPosition, CurrentY);

            // Set Invoice Table:
            CurrentY = CurrentY + InvoiceFontHeight + 8;

            while (CurrentRecord &lt; RecordsPerPage)
            {

                    FieldValue = dr["cfname"].ToString();
                    g.DrawString(FieldValue, InvoiceFont, BlackBrush, xCustomerName, CurrentY);
                    FieldValue = dr["cfno"].ToString();

                    // if Length of (Product Name) &gt; 20, Draw 20 character only
                    if (FieldValue.Length &gt; 20)

                        FieldValue = FieldValue.Remove(20, FieldValue.Length - 20);
                    g.DrawString(FieldValue, InvoiceFont, BlackBrush, xNumber, CurrentY);

                    FieldValue = String.Format(dr["cfaddress"].ToString());
                    g.DrawString(FieldValue, InvoiceFont, BlackBrush, xAddress, CurrentY);

                    FieldValue = dr["cfspecialization"].ToString();
                    g.DrawString(FieldValue, InvoiceFont, BlackBrush, xSpecialization, CurrentY);



                    CurrentY = CurrentY + InvoiceFontHeight;

                    if (!dr.Read())
                    {
                        StopReading = true;
                        break;
                    }

                    CurrentRecord++;
                }

            if (CurrentRecord &lt; RecordsPerPage)
                e.HasMorePages = false;
            else
                e.HasMorePages = true;

            if (StopReading)
            {
                dr.Close();
                con.Close();
                SetInvoiceTotal(g);
            }

            g.Dispose();
        }
</code></pre>

<p><strong>2nd step:</strong></p>

<pre><code> private void SetInvoiceData(Graphics g, System.Drawing.Printing.PrintPageEventArgs e)
        {
            // Set Invoice Table:
            string FieldValue = "";
            int CurrentRecord = 0;
            int RecordsPerPage = 20; // twenty items in a page
            decimal Amount = 0;
            bool StopReading = false;

            // Set Table Head:
            int xItems = leftMargin;
            CurrentY = CurrentY + InvoiceFontHeight;

            g.DrawString("Items", InvoiceFont, BlueBrush, xItems, CurrentY);
            int xQty = xItems + (int)g.MeasureString("Items", InvoiceFont).Width + 4;

            g.DrawString("Qty", InvoiceFont, BlueBrush, xQty, CurrentY);
            int xPrice = xQty + (int)g.MeasureString("Qty", InvoiceFont).Width + 72;

            g.DrawString("Price", InvoiceFont, BlueBrush, xPrice, CurrentY);
            int xSubTotal = xPrice + (int)g.MeasureString("Price", InvoiceFont).Width + 4;

            g.DrawString("SubTotal", InvoiceFont, BlueBrush, xSubTotal, CurrentY);
            //int xSpecialization = xAddress + (int)g.MeasureString("Specialization", InvoiceFont).Width + 4;

            // g.DrawString("Discount", InvoiceFont, BlueBrush, xSpecialization, CurrentY);

            AmountPosition = xSubTotal + (int)g.MeasureString("SubTotal", InvoiceFont).Width + 4;
            //g.DrawString("Extended Price", InvoiceFont, BlueBrush, AmountPosition, CurrentY);

            // Set Invoice Table:
            CurrentY = CurrentY + InvoiceFontHeight + 8;



            while (CurrentRecord &lt; RecordsPerPage)
            {


                    foreach (DataGridViewRow row in itemgridview.Rows)
                    {
                        FieldValue = row.Cells[0].Value.ToString();
                        // FieldValue = itemgridview.Rows["items"].ToString();
                        g.DrawString(FieldValue, InvoiceFont, BlackBrush, xItems, CurrentY);


                        //FieldValue = dr["itmqty"].ToString();
                        FieldValue = row.Cells[1].Value.ToString();

                        // if Length of (Product Name) &gt; 20, Draw 20 character only
                        if (FieldValue.Length &gt; 20)

                            FieldValue = FieldValue.Remove(20, FieldValue.Length - 20);
                        g.DrawString(FieldValue, InvoiceFont, BlackBrush, xQty, CurrentY);

                        //FieldValue = String.Format(dr["itemprice"].ToString());
                        FieldValue = row.Cells[2].Value.ToString();
                        g.DrawString(FieldValue, InvoiceFont, BlackBrush, xPrice, CurrentY);

                        //FieldValue = dr["subtotal"].ToString();
                        FieldValue = row.Cells[3].Value.ToString();
                        g.DrawString(FieldValue, InvoiceFont, BlackBrush, xSubTotal, CurrentY);


                        CurrentY = CurrentY + InvoiceFontHeight;


                        if (itemgridview.Rows.Count == 0)
                        {
                            StopReading = true;
                            break;
                        //StopReading = true;

                        // return;
                        }


                        CurrentRecord++;

                }
            }



            if (CurrentRecord &lt; RecordsPerPage)
                e.HasMorePages = false;
            else
                e.HasMorePages = true;

            if (StopReading)
            {
               // dr.Close();
                //con.Close();
                SetInvoiceTotal(g);
            }

            g.Dispose();
        }
</code></pre>
