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