How to print DataGrid control?

netnoon

New member
Joined
Feb 15, 2006
Messages
3
Programming Experience
Beginner
Hi all,
could please help? I am very newbie to .net programming and can´t solve the problem of datagrid control print.

I use this simple code to print the datagrid control but do not know how to print more then one page. I have tried to set the property HasMorePages = true based on height od the grid but all I have achieved was to print the first page multiple times.

Could you please advise or send hyperlink where I can find something helpful ?

If there is any way how to print directly from dataSet I would appreciate any your help.

Thanks a lot


PrivateSub PrintGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tisk_button.Click
printdocument1.Print()
EndSub
PrivateSub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printdocument1.PrintPage

Dim myPaintArgs AsNew PaintEventArgs(e.Graphics, New Rectangle(New Point(0, 0), Me.Size))
Me.InvokePaint(datagrid, myPaintArgs)
EndSub

 
Hi,
I have this example, I copied from somewhere on the internet, never tried it. Maybe would help you. I am pasting it hereunder:

VB .NET example:
Private PrintGrid As DataGridPrint
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim fpr As New frmPrint()
With fpr
.Title = DataGrid1.CaptionText
.ShowDialog()
If .Result > 0 Then
PrintGrid = New DataGridPrint(PrintDocument1, 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

' Specify the output to print by handling the PrintPage event
' and by using the Graphics included in the PrintPageEventArgs.
Private Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
' Print method of DataGridPrint class starts the custom datagrid's printing process.
e.HasMorePages = PrintGrid.Print(e.Graphics)
End Sub
 
Back
Top