IMPRIMIR DATAGRIDVIEW NO VISUAL BASIC 2008
Boas
Tenho este código para imprimir o meu datagridview. Mas ele não imprimir completo.
Como fazo para imprimir o datagrid view todo e com cabeçalhos?
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If PrintDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim bm As New Bitmap(Me.DataGridView2.Width, Me.DataGridView2.Height)
DataGridView2.DrawToBitmap(bm, New Rectangle(0, 0, Me.DataGridView2.Width, Me.DataGridView2.Height))
e.Graphics.DrawImage(bm, 100, 50)
End Sub
Tenho este código para imprimir o meu datagridview. Mas ele não imprimir completo.
Como fazo para imprimir o datagrid view todo e com cabeçalhos?
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If PrintDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.PrinterSettings.DefaultPageSettings.Landscape = True
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim bm As New Bitmap(Me.DataGridView2.Width, Me.DataGridView2.Height)
DataGridView2.DrawToBitmap(bm, New Rectangle(0, 0, Me.DataGridView2.Width, Me.DataGridView2.Height))
e.Graphics.DrawImage(bm, 100, 50)
End Sub
Bom dia ,
Veja se isso lhe ajuda
http://www.rustemsoft.com/print_datagrid.asp
Até mais.
Veja se isso lhe ajuda
http://www.rustemsoft.com/print_datagrid.asp
Até mais.
Boas
Obrigado pela resposta
Eu escrevo Private PrintGrid As DataGridPrint ele diz-me que não está declarado... :/
Como posto esses código?
Obrigado pela resposta
Eu escrevo Private PrintGrid As DataGridPrint ele diz-me que não está declarado... :/
Como posto esses código?
De uma olhada aqui tambem !
http://vb.net-informations.com/datagridview/vb.net_datagridview_printing.htm
Abraços
http://vb.net-informations.com/datagridview/vb.net_datagridview_printing.htm
Abraços
Já segui esse tópico mas ele não faz cabeçalhos nem imprime todas as colunas do datagrid view.
Neste momento tenho este código:
Mas da-me os seguinte erros:
Error 1 Type [ô]DataGridPrinter[ô] is not defined.
Error 2 Type [ô]frmPrint[ô] is not defined.
Error 3 Type [ô]DataGridPrint[ô] is not defined.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fpr As New frmPrint()
With fpr
.Title = DataGrid1.CaptionText
.ShowDialog()
If .Result > 0 Then
PrintGrid = New DataGridPrint(PrintDocument3, DataGrid1, .bBlackWhite)
PrintGrid.PrintTitle = .bTitle
PrintGrid.Title = .Title
Select Case .Result
Case 1 [ô] Print
[ô] The Print method prints the datagrid without using a print dialog.
[ô] Use a PrintDialog when you want to offer the user the ability to choose print settings.
If PrintDialog1.ShowDialog() = DialogResult.OK Then PrintDocument1.Print()
Case 2 [ô] Page Setup
PageSetupDialog1.ShowDialog()
Case 3 [ô] Preview
PrintPreviewDialog1.Icon = fpr.Icon
PrintPreviewDialog1.ShowDialog()
End Select
End If
End With
End Sub
Private Sub PrintDocument3_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument3.PrintPage
e.HasMorePages = PrintGrid.Print(e.Graphics)
End Sub
End Class
Neste momento tenho este código:
Mas da-me os seguinte erros:
Error 1 Type [ô]DataGridPrinter[ô] is not defined.
Error 2 Type [ô]frmPrint[ô] is not defined.
Error 3 Type [ô]DataGridPrint[ô] is not defined.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fpr As New frmPrint()
With fpr
.Title = DataGrid1.CaptionText
.ShowDialog()
If .Result > 0 Then
PrintGrid = New DataGridPrint(PrintDocument3, DataGrid1, .bBlackWhite)
PrintGrid.PrintTitle = .bTitle
PrintGrid.Title = .Title
Select Case .Result
Case 1 [ô] Print
[ô] The Print method prints the datagrid without using a print dialog.
[ô] Use a PrintDialog when you want to offer the user the ability to choose print settings.
If PrintDialog1.ShowDialog() = DialogResult.OK Then PrintDocument1.Print()
Case 2 [ô] Page Setup
PageSetupDialog1.ShowDialog()
Case 3 [ô] Preview
PrintPreviewDialog1.Icon = fpr.Icon
PrintPreviewDialog1.ShowDialog()
End Select
End If
End With
End Sub
Private Sub PrintDocument3_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument3.PrintPage
e.HasMorePages = PrintGrid.Print(e.Graphics)
End Sub
End Class
Tópico encerrado , respostas não são mais permitidas