title: Use PrintDocument to print each row in DataTable to seperate page
body: <p>I have an application with a <code>DataTable</code> and I need to print each row in the <code>DataTable</code> to a separate page and I'm having a hell of a time trying to get it to work. I've found plenty of posts related to <em>printing more than one page</em> and <em>printing DataGridViews</em> but I can't find anything about printing each row in a <code>DataTable</code> to separate pages.</p>
  
  <p>Anyways, here is what I have put together so far and it doesn't quite work.</p>
  
  <pre><code>private void btnPrint_Click(object sender, EventArgs e)
  {
      printTag.DefaultPageSettings.Landscape = true;
      PrintPreviewDialog preview = new PrintPreviewDialog();
      preview.Document = printTag;
      preview.Show();
  }
  
  private void printTag_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
  {
      PrintRow = 0;
      //Here I set my Fonts, String Formats and Pen Styles
  
      int maxRows = _dtTags.Rows.Count;
      for (int lines = 0; lines &lt; maxRows; ++lines)
      {
          PrintRow++;
          if (PrintRow &gt;= _dtTags.Rows.Count)
          {
              e.HasMorePages = PrintRow &lt; _dtTags.Rows.Count;
              return; //Done Printing
          }
  
          var row = _dtTags.Rows[PrintRow];
  
          //Pass data from current Row of DataTable to variables which are used to populate the e.Graphic
          jobNum = _dsTags.Tables["Paint Tags"].Rows[lines].Field&lt;string&gt;("Job");
          machInfo = _dsTags.Tables["Paint Tags"].Rows[lines].Field&lt;string&gt;("Job Desc");
          jobNote = _dsTags.Tables["Paint Tags"].Rows[lines].Field&lt;string&gt;("Job Note");
          color = _dsTags.Tables["Paint Tags"].Rows[lines].Field&lt;string&gt;("Color");
          parts = _dsTags.Tables["Paint Tags"].Rows[lines].Field&lt;string&gt;("Parts");
          empName = _dsTags.Tables["Paint Tags"].Rows[lines].Field&lt;string&gt;("Employee");
  
          //Here my e.Graphic is created, located and filled out
  
      }
  }
  </code></pre>
  
  <p>So, here is what it does with the above code:</p>
  
  <ol>
  <li>If my table has only has one row the print preview comes out blank.</li>
  <li>If my table has more than one row, the last row isn't printed.</li>
  <li>Each row in the table (with the exception of the last and if there is only one) prints on the same page.</li>
  </ol>
  
  <p>So basically my preview looks like I fed the same paper into the printer multiple times and printed over it.</p>
  
  <p>Any help or advice on getting this to work would be immensely appreciated.</p>