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. Printing Datagridview content plus header and footer in vb.net 2010

Printing Datagridview content plus header and footer in vb.net 2010

Scheduled Pinned Locked Moved Visual Basic
helpcsharpquestion
3 Posts 2 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.
  • S Offline
    S Offline
    sali22
    wrote on last edited by
    #1

    Dear Friends, i have problem by printing Datagridview content plus header and footer. i can print exactly DataGridView , but i want to print out the content only (plain text)+ header and footer in vb.net 2010 is anybody can help me to do this !? Your help would be greatly appreciated Thanks in advance

    A S 2 Replies Last reply
    0
    • S sali22

      Dear Friends, i have problem by printing Datagridview content plus header and footer. i can print exactly DataGridView , but i want to print out the content only (plain text)+ header and footer in vb.net 2010 is anybody can help me to do this !? Your help would be greatly appreciated Thanks in advance

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      A couple of existing solutions that should help you out - Printing a DataGridView on DotNet Framework[^] A class to print and print preview a DataGrid control[^]

      WP7.5 Apps - XKCD | Calvin | SMBC | Sound Meter | Speed Dial

      1 Reply Last reply
      0
      • S sali22

        Dear Friends, i have problem by printing Datagridview content plus header and footer. i can print exactly DataGridView , but i want to print out the content only (plain text)+ header and footer in vb.net 2010 is anybody can help me to do this !? Your help would be greatly appreciated Thanks in advance

        S Offline
        S Offline
        sali22
        wrote on last edited by
        #3

        Static oColumnLefts As New ArrayList Static oColumnWidths As New ArrayList Static oColumnTypes As New ArrayList Static nHeight As Int16 Dim nWidth, i, nRowsPerPage As Int16 Dim nTop As Int16 = e.MarginBounds.Top Dim nLeft As Int16 = e.MarginBounds.Left If nPageNo = 1 Then For Each oColumn As DataGridViewColumn In frmLedger.dgvLedger.Columns nWidth = CType(Math.Floor(oColumn.Width / nTotalWidth * nTotalWidth * (e.MarginBounds.Width / nTotalWidth)), Int16) nHeight = e.Graphics.MeasureString(oColumn.HeaderText, oColumn.InheritedStyle.Font, nWidth).Height + 11 oColumnLefts.Add(nLeft) oColumnWidths.Add(nWidth) oColumnTypes.Add(oColumn.GetType) nLeft += nWidth Next End If Do While nRowPos < frmLedger.dgvLedger.Rows.Count - 1 Dim oRow As DataGridViewRow = frmLedger.dgvLedger.Rows(nRowPos) If nTop + nHeight >= e.MarginBounds.Height + e.MarginBounds.Top Then DrawFooter(e, nRowsPerPage) NewPage = True nPageNo += 1 e.HasMorePages = True Exit Sub Else If NewPage Then ' Draw Header e.Graphics.DrawString(Header, New Font(frmLedger.dgvLedger.Font, FontStyle.Bold), Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top - e.Graphics.MeasureString(Header, New Font(frmLedger.dgvLedger.Font, FontStyle.Bold), e.MarginBounds.Width).Height - 13) ' Draw Columns nTop = e.MarginBounds.Top i = 0 For Each oColumn As DataGridViewColumn In frmLedger.dgvLedger.Columns e.Graphics.FillRectangle(New SolidBrush(Drawing.Color.LightGray), New Rectangle(oColumnLefts(i), nTop, oColumnWidths(i), nHeight)) e.Graphics.DrawRectangle(Pens.Black, New Rectangle(oColumnLefts(i), nTop, oColumnWidths(i), nHeight)) e.Graphics.DrawString(oColumn.HeaderText, oColumn.InheritedStyle.Font, New SolidBrush(oColumn.InheritedStyle.ForeColor), New RectangleF(oColumnLefts(i), nTop, oColumnWidths(i), nHeight), oStringFormat) i += 1 Next NewPage = False End If nTop += nHeight i = 0 For Each oCell As Data

        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