Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to print a grid

How to print a grid

Scheduled Pinned Locked Moved Visual Basic
csstutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pdcoope
    wrote on last edited by
    #1

    I have produced a grid from 2 tables that has been formated and displays about 100 rows of information (Each row has 30 cols). I would like to be able to print the grid. Has anyone any ideas how to do this or to point me in the right direction. Thanks in advance. Peter

    D J 2 Replies Last reply
    0
    • P pdcoope

      I have produced a grid from 2 tables that has been formated and displays about 100 rows of information (Each row has 30 cols). I would like to be able to print the grid. Has anyone any ideas how to do this or to point me in the right direction. Thanks in advance. Peter

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This[^] little example on MSDN might get you started. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      A 1 Reply Last reply
      0
      • P pdcoope

        I have produced a grid from 2 tables that has been formated and displays about 100 rows of information (Each row has 30 cols). I would like to be able to print the grid. Has anyone any ideas how to do this or to point me in the right direction. Thanks in advance. Peter

        J Offline
        J Offline
        Just Greeky Creek
        wrote on last edited by
        #3

        Try this Dim ActivePageNumber As Short = 1 Dim pageCount As Short = 0 Dim ItemCountOnPerPage As Integer = 30 Dim dtSource As DataTable Dim index As Short Private Sub btnPrintDataGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintDataGrid.Click ActivePageNumber = 1 pageCount = Math.Ceiling(dtSource.Rows.Count / ItemCountOnPerPage) PrintDocument1.Print() End Sub Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage If Not ActivePageNumber > pageCount Then PrintDataTable(e.Graphics) ActivePageNumber += 1 e.HasMorePages = True Else e.HasMorePages = False End If End Sub Public Sub PrintDataTable(ByVal e As Graphics) Dim x, y As Short Dim fArial As New Font("Arial", 8) x = 20 y = 20 Dim cci As Short = index Do While (cci <> ItemCountOnPerPage Or index <> dtSource.Rows.Count - 1) For columnIndex As Short = 0 To dtSource.Columns.Count - 1 e.DrawString(dtSource.Rows(index)(columnIndex), fArial, New SolidBrush(Color.Black), x, y) x += 30 ' set this to column width Next y += fArial.Height cci += 1 index += 1 Loop End Sub

        A 1 Reply Last reply
        0
        • D Dave Kreskowiak

          This[^] little example on MSDN might get you started. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Mny tks for the help - will try it.

          1 Reply Last reply
          0
          • J Just Greeky Creek

            Try this Dim ActivePageNumber As Short = 1 Dim pageCount As Short = 0 Dim ItemCountOnPerPage As Integer = 30 Dim dtSource As DataTable Dim index As Short Private Sub btnPrintDataGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintDataGrid.Click ActivePageNumber = 1 pageCount = Math.Ceiling(dtSource.Rows.Count / ItemCountOnPerPage) PrintDocument1.Print() End Sub Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage If Not ActivePageNumber > pageCount Then PrintDataTable(e.Graphics) ActivePageNumber += 1 e.HasMorePages = True Else e.HasMorePages = False End If End Sub Public Sub PrintDataTable(ByVal e As Graphics) Dim x, y As Short Dim fArial As New Font("Arial", 8) x = 20 y = 20 Dim cci As Short = index Do While (cci <> ItemCountOnPerPage Or index <> dtSource.Rows.Count - 1) For columnIndex As Short = 0 To dtSource.Columns.Count - 1 e.DrawString(dtSource.Rows(index)(columnIndex), fArial, New SolidBrush(Color.Black), x, y) x += 30 ' set this to column width Next y += fArial.Height cci += 1 index += 1 Loop End Sub

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Mny tks - will try it out. Peter

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups