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