我有一個Datagrid,其中包含從數據庫中檢索的信息,我希望打印輸出爲帶有行和列的表格格式。我的實際方法很簡單,但輸出很混亂。有什麼想法嗎?如何打印Datagridview在VB中有一個表格
Private Sub Imprimir_Click(sender As Object, e As EventArgs) Handles Imprimir.Click
PrintPreviewDialog1.PrintPreviewControl.Zoom = 1.0
PrintPreviewDialog1.FindForm.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim y As Integer = 70
PrintDocument1.DefaultPageSettings.Landscape = True
e.Graphics.DrawString("TransporGest - Registo de Operações",
New Font("Verdana", 10, FontStyle.Bold), Brushes.Black, 30, 30)
For Each dr As DataGridViewRow In dg.Rows
e.Graphics.DrawString(dr.Cells(0).Value & " | " & dr.Cells(2).Value &
" | " & dr.Cells(3).Value & " | " & dr.Cells(4).Value & " | " &
dr.Cells(6).Value & " | " & dr.Cells(7).Value & " | " &
dr.Cells(9).Value & " | " & dr.Cells(11).Value & " | " &
dr.Cells(12).Value, New Font("Verdana", 10), Brushes.Black, 30, y)
y += 20
Next
End Sub
End Class
您可以打印ooopsoft的工作方式,但在我看來,reportviewer在datagridview打印方面是一個更容易的選擇,但這只是我的看法。 – user3758070
我已經用水晶報告了我的報告!超級簡單!不過,我需要以某種形式使用我的sql查詢。有什麼辦法可以改變VB上的水晶報表查詢嗎? –
我最近與reportviewer很多,所以讓我知道如果你有任何更多的問題:) – user3758070