I have a question about printing a grid. I have a grid where the user cant select mulitple rows in a range. so they can highlight one row at a time and this is only for so they can delete a row. my question is this. this grid can have anywhere from 1 to 128 rows. if the user only has data in 4 rows then thats all i want to print when i print the grid. with the code im pasting below it prints the whole grid so i get four pages showing all 128 rows and only 4 have data. so is there some way behind the scenes i can do a selection before the following print code or some other wasy to say only print X amount of rows???
#Region "Print code"
Private Sub btnPrintGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintGrid.Click
Try
Dim PD As New GridPrintDocument(grdDateRange) ''''''Assumes the default printer
Dim DLG As New PrintDialog
DLG.Document = PD
DLG.AllowSelection = True
DLG.AllowSomePages = True
AddHandler PD.PrintPage, AddressOf Me.PrintPagehandler
If DLG.ShowDialog = DialogResult.OK Then
PD.Print()
End If
PD.Dispose()
DLG.Dispose()
Catch ex As Exception
MessageBox.Show(ex.ToString() & ControlChars.CrLf & ControlChars.CrLf & "Click OK to continue.", "An error occurred while printing", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub PrintPagehandler(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
Dim yPos As Single = 0
Dim count As Integer = 0
Dim topMargin As Single = e.MarginBounds.Top - 75
'''''' Create font and brush.
Dim Head1Font As New Font("Letter Gothic", 14, FontStyle.Bold) ''''''QUASAR Header
Dim LineFont As New Font("Letter Gothic", 12, FontStyle.Regular) ''''''Date/Time stamp
''''''add title
yPos = topMargin + (count * Head1Font.GetHeight(e.Graphics))
e.Graphics.DrawString(fMDIForm1.Text, Head1Font, Brushes.Black, e.MarginBounds.Left, yPos, New StringFormat)
count = count + 1
''''''add date and time stamp
yPos = topMargin + (count * LineFont.GetHeight(e.Graphics))
e.Graphics.DrawString(DateTime.Now.ToString, LineFont, Brushes.Black, e.MarginBounds.Left, yPos, New StringFormat)
End Sub
#End Region
AD
Administrator
Syncfusion Team
March 9, 2005 01:59 PM
One stright-forward way to handle this is to subscribe to the grid.QueryRowHeight event.
In that event, if grid.PrintingMode is true, then check the row pointed to by e.Index. If you do not want to print this row, then set e.Size = 0 and e.Handled = true. This will essentially hide any row that you do not want to print (and only do it while you are printing).
PB
Philip Bishop
March 9, 2005 02:19 PM
Once again exactly what i wanted, you''re the man. Is there any documentation that would of told me thats what that event can do for me? If so i couldnt find it.
AD
Administrator
Syncfusion Team
March 9, 2005 02:48 PM
This idea is described in this KB.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=66&catId=7
PB
Philip Bishop
March 9, 2005 04:03 PM
I guess i didnt know that existed! Thanks