1
I am creating a Vb.net report with my Datagrid data and trying to send it to print. However in this project I am using two Datagrids , one for a table Report , and another for the table Report.
the code I usually use for printing a Datagrid would be this :
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim g As Graphics = e.Graphics
Dim PosicaoLinha As Integer = 40
Dim LinhasPorPagina As Byte = 45
Dim total As String = String.Empty
Dim grupo As String = String.Empty
Dim valor As String = String.Empty
Dim unidade As String = String.Empty
'Definições da pagina
g.PageUnit = GraphicsUnit.Millimeter
'Desenhar folha
Dim Titulo As New Font("Arial", 4, FontStyle.Regular, GraphicsUnit.Millimeter)
g.DrawString("*** Resumo de vendas por Grupo *** ", Titulo, Brushes.Black, 10, 20)
For L = 0 To LinhasPorPagina - 1
If LinhaAtual = RELATORIDataGridView.Rows.Count Then Continue For
For i As Integer = 0 To RELATORIDataGridView.ColumnCount - 5
If Not RELATORIDataGridView.Item(i, LinhaAtual).Value = Nothing Then
grupo = RELATORIDataGridView.Item(i, LinhaAtual).Value
End If
Next
For i As Integer = 0 To RELATORIDataGridView.ColumnCount - 3
If Not RELATORIDataGridView.Item(i, LinhaAtual).Value = Nothing Then
unidade = RELATORIDataGridView.Item(i, LinhaAtual).Value
End If
Next
For i As Integer = 0 To RELATORIDataGridView.ColumnCount - 4
RELATORIDataGridView.Columns(4).DefaultCellStyle.Format = "C2"
If Not RELATORIDataGridView.Item(i, LinhaAtual).Value = Nothing Then
valor = RELATORIDataGridView.Item(i, LinhaAtual).Value
End If
Next
'Desenhar conteudo na página
e.Graphics.DrawString("Grupo", New Font("Verdana", 6), Brushes.Black, 20, 30)
e.Graphics.DrawString(grupo, New Font("Verdana", 6), Brushes.Black, 20, PosicaoLinha)
e.Graphics.DrawString("Unidades", New Font("Verdana", 6), Brushes.Black, 40, 30)
e.Graphics.DrawString(unidade, New Font("Verdana", 6), Brushes.Black, 40, PosicaoLinha)
e.Graphics.DrawString("Valor", New Font("Verdana", 6), Brushes.Black, 60, 30)
e.Graphics.DrawString(valor, New Font("Verdana", 6), Brushes.Black, 60, PosicaoLinha)
e.Graphics.DrawString("______________________________________________________________________________________________________________________________", New Font("Verdana", 8), Brushes.Black, 0, 34)
PosicaoLinha += 5
LinhaAtual += 1
valor = String.Empty
grupo = String.Empty
unidade = String.Empty
total = String.Empty
Next
e.Graphics.DrawString("Totais: ", New Font("Verdana", 6), Brushes.Black, 20, PosicaoLinha)
e.Graphics.DrawString(lblTotalUnidade.Text, New Font("Verdana", 6), Brushes.Black, 40, PosicaoLinha)
e.Graphics.DrawString(lblTotalValor.Text, New Font("Verdana", 6), Brushes.Black, 60, PosicaoLinha)
End Sub
Could someone tell me how I include one more Datagrid in this code for printing ?
If you import, I’m using Access as a base.