Here is some code that I wrote to print the contents of a GlacialListview (which is very similar to the MS Listview - you can download the V1.5 version free from
This will (currently) only print in landscape but it will give you a starting point...
Private tx As Integer
Private i As Integer
Private Y As Integer
Private titf As Font
Private tabf As Font
Private itm As Integer
Private start As Integer
Private pagenum As Integer
Private pageWidth As Integer
Private pageHeight As Integer
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim sMainTitle As String
Dim iColWidth As Integer
Dim iCellH As Integer = 18
Dim iCellW As Integer
Dim blackPen As New Pen(Color.Gray, 0.5)
Dim ControlBrush As New SolidBrush(Color.FromName("Control"))
Dim imgH As Image
Y = Y + 30
For i = 0 To grdUserDets.Columns.Count - 1
iCellW = grdUserDets.Columns(i).Width()
e.Graphics.FillRectangle(ControlBrush, tx, Y, iCellW, iCellH)
e.Graphics.DrawRectangle(blackPen, tx, Y, iCellW, iCellH)
If iCellW > 0 Then
If Not IsDBNull(grdUserDets.Columns(i).Text) Then
e.Graphics.DrawString(grdUserDets.Columns(i).Text, titf, Brushes.Black, tx, Y)
End If
End If
tx += iCellW '80
Next
Y = Y + 30
For itm = start To grdUserDets.Items.Count - 1
tx = 80
For i = 0 To grdUserDets.Columns.Count - 1
iCellW = grdUserDets.Columns(i).Width()
If iCellW > 0 Then
Dim p1 As String
Dim q1 As Decimal
Dim iIndex As Integer
Dim img As Image
Dim bImgFound As Boolean
iIndex = grdUserDets.Items(itm).SubItems(i).ImageIndex
If iIndex <> -1 Then
iIndex = grdUserDets.Items(itm).SubItems(i).ImageIndex
img = imgMain.Images(iIndex)
bImgFound = True
Else
p1 = grdUserDets.Items(itm).SubItems(i).Text
bImgFound = False
End If
q1 = tx
If bImgFound Then
e.Graphics.DrawImage(img, q1, Y)
e.Graphics.DrawRectangle(blackPen, tx, Y, iCellW, iCellH)
Else
If i = 0 Then 'This is the first column...
e.Graphics.FillRectangle(ControlBrush, tx, Y, iCellW, iCellH)
e.Graphics.DrawRectangle(blackPen, tx, Y, iCellW, iCellH)
End If
e.Graphics.DrawRectangle(blackPen, tx, Y, iCellW, iCellH)
e.Graphics.DrawString(p1, tabf, Brushes.Black, q1, Y)
End If
End If
tx += iCellW '80
Next
Y = Y + 18
With PrintDocument1.DefaultPageSettings
If Y > 720 Then
pagenum += 1
Y = Y + 5
e.Graphics.DrawString("Page " & pagenum, titf, Brushes.Black, pageWidth / 2, Y)
e.HasMorePages = True
start = itm + 1
If start > grdUserDets.Items.Count - 1 Then
Exit For
End If
Exit Sub
End If
End With
Next
End Sub
Private Sub doprint()
With PrintDocument1.DefaultPageSettings
.Landscape = True
pageWidth = .PaperSize.Height - _
.Margins.Left - _
.Margins.Right
End With
PrintDocument1.DefaultPageSettings.Margins.Left = 60
start = 0
tabf = New Font("Arial", 8)
titf = New Font("Arial", 9, FontStyle.Bold Or FontStyle.Underline)
tx = 60
pagenum = 0
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.