title: How to print Datagridview has a table in VB
body: <p>I have a Datagrid with information retrieved from a database and i would like the print output to be in table format with lines and columns. My actual methode is simple but the output is very confusing. Any thoughts? </p>
  
  <pre><code>  Private Sub Imprimir_Click(sender As Object, e As EventArgs) Handles Imprimir.Click
      PrintPreviewDialog1.PrintPreviewControl.Zoom = 1.0
      PrintPreviewDialog1.FindForm.WindowState = FormWindowState.Maximized
      PrintPreviewDialog1.ShowDialog()
    End Sub
  
    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As 
        System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim y As Integer = 70
        PrintDocument1.DefaultPageSettings.Landscape = True
        e.Graphics.DrawString("TransporGest - Registo de Operações", 
            New Font("Verdana", 10, FontStyle.Bold), Brushes.Black, 30, 30)
        For Each dr As DataGridViewRow In dg.Rows
          e.Graphics.DrawString(dr.Cells(0).Value &amp; " | " &amp; dr.Cells(2).Value &amp; 
               " | " &amp; dr.Cells(3).Value &amp; " | " &amp; dr.Cells(4).Value &amp; " | " &amp;
               dr.Cells(6).Value &amp; " | " &amp; dr.Cells(7).Value &amp; " | " &amp; 
               dr.Cells(9).Value &amp; " | " &amp; dr.Cells(11).Value &amp; " | " &amp; 
               dr.Cells(12).Value, New Font("Verdana", 10), Brushes.Black, 30, y)
          y += 20
      Next
    End Sub
  End Class
  </code></pre>