Link to home
Start Free TrialLog in
Avatar of yulyos
yulyosFlag for Israel

asked on

How can i print ListView report to the printer.

I writing a program in VB6.

I make a report from ListView:
ListView.View = lvwReport, with 6 columns.

My question is:
How can i print to the printer the report.

thanking you in advance

From:
yulyos@yahoo.com
www.go.to/yulyos
ASKER CERTIFIED SOLUTION
Avatar of raizon
raizon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Benjy
Benjy

This subroutine prints the contents of a ListView control in report view. The parameter Lines specifies the number of rows that will be printed, beginning with the first row. If LV.ListCount is less than the parameter Lines, then all the rows will be printed. The columns in the LV control are tabbed to be uniformly distributed across the page.

Public Sub PrintListView(LV As ListView, Lines%)
    Dim i%, LVWidth%, NewTab%, j%
    Dim itmX As ListItem
    Dim LineCount%
   
    LVWidth = 0
    For i = 1 To LV.ColumnHeaders.Count
        LVWidth = LVWidth + LV.ColumnHeaders(i).Width
    Next
    NewTab = 0
    For i = 1 To LV.ColumnHeaders.Count
        NewTab = NewTab + CInt(LV.ColumnHeaders(i).Width * Printer.ScaleWidth / LVWidth)
        Printer.Print LV.ColumnHeaders(i).Text;
        Printer.CurrentX = NewTab
    Next
    Printer.Print
    If Lines < LV.ListItems.Count And Lines <> 0 Then
        LineCount = Lines
    Else
        LineCount = LV.ListItems.Count
    End If
    For i = 1 To LineCount
        NewTab = 0
        Set itmX = LV.ListItems(i)
        Printer.Print itmX.Text;
        For j = 1 To LV.ColumnHeaders.Count - 1
            NewTab = NewTab + CInt(LV.ColumnHeaders(j).Width * Printer.ScaleWidth / LVWidth)
            Printer.CurrentX = NewTab
            Printer.Print itmX.SubItems(j);
        Next
        Printer.Print
    Next
 
End Sub