How to print a grid
-
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
-
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
-
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
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
-
-
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