Animesh Datta

Animesh Datta

  • 1.2k
  • 194
  • 99.8k

How to print dataset in multiple pages in Windows form

Feb 18 2013 7:21 AM
Hi Everyone.......
 
I want to print a data-set in windows form application . In my dataset there are 5 rows and 3 columns , and i want to print two rows per pages .means there will be 3 pages to print whole data-set. My code is

float CurrentX = 20;//This is for X axis
float CurrentY = 100; //This is for Y axis
 int linesPerPage = 2; int count = 0;
 private void printDocument1_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
{
 foreach (DataRow Dr in ds.Tables[0].Rows)
 {
   foreach (DataColumn dc in ds.Tables[0].Columns)
     { e.Graphics.DrawString(Dr[dc].ToString(), DefaultFont, Brushes.Black, CurrentX,  CurrentY);
    CurrentX = CurrentX + 50;//Increment of X axis by 50
    }
  CurrentY = CurrentY + 100;//Increment of Y axis by 100 for new row
  CurrentX = 20; //Initialize the X axis for start the same position
  count = count + 1;//Increment the count
  if (count > linesPerPage)
  {
    e.HasMorePages = true;
   }
 else e.HasMorePages = false;
}
  }


But here number of pages in going to infinity and result is not coming . actually
e.HasMorePages logic is not cleared to me, i try to implement the logic but every time i failed. Where is the mistake , please suggest some things .
 
Thank You....