
listview printing in vb 6 sp5
Hi Geoffrey,
I haven't even messed around with PrintForm since the first time I tried it in VB2 or something. There may be a good use for it, but I've yet to find it. The Printer Object is really easy to learn and gives you complete control of the output, give it a whirl...
Start a new project and Double-click a ListView onto a form and double-click a Command Button onto it also, (the code will do the rest)
Paste the following code under the form:
--------------------------------------------------------------------------------
Option Explicit
Private Sub Form_Load()
Dim Ite As Integer
On Error Resume Next
BorderStyle = 3
BackColor = vbButtonFace
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2, 4440, 3400
Caption = "Printer Object ListView Test"
Command1.Caption = "&Print"
With ListView1
.GridLines = True
.FullRowSelect = True
.BorderStyle = ccNone
.HotTracking = True
.HoverSelection = True
.Appearance = ccFlat
.BackColor = vbButtonFace
.ForeColor = vbButtonText
.HideSelection = False
.Move 0, 0, ScaleWidth, ScaleHeight - 500
.View = lvwReport
.ColumnHeaders.Add , , "Col1"
.ColumnHeaders.Add , , "Col2"
.ColumnHeaders.Add , , "Col3"
Command1.Move (ScaleWidth - Command1.Width) / 2, .Height, 1000, 400
For Ite = 1 To 10
.ListItems.Add , , Ite & "A"
.ListItems(.ListItems.Count).ListSubItems.Add , , Ite & "B"
.ListItems(.ListItems.Count).ListSubItems.Add , , Ite & "C"
Next
End With
End Sub
Private Sub Command1_Click()
Dim Ite As Integer
On Error Resume Next
With ListView1
Printer.FontSize = 22
Printer.FontBold = True
Printer.Print " My Report"
Printer.FontSize = 12
Printer.FontBold = False
Printer.Print
For Ite = 1 To .ListItems.Count
Printer.Print .ListItems(Ite)
Printer.Print .ListItems(Ite).ListSubItems(1)
Printer.Print .ListItems(Ite).ListSubItems(2)
Printer.Print
Next
'Now the Print Job is Buffered and ready to send to the printer.
Printer.EndDoc
End With
End Sub
--------------------------------------------------------------------------------
You can see I have way too much time on my hands today ;o)
hth...
s