Solved

How can i print ListView report to the printer.

Posted on 2002-06-13
3
4,306 Views
Last Modified: 2011-08-26
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
0
Comment
Question by:yulyos
3 Comments
 
LVL 5

Accepted Solution

by:
raizon earned 100 total points
ID: 7077220
loop through the listview.listitems.count concantinating each subitem into a string and then send the string to the printer.

Private Sub mnuFilePrint_Click()
    Dim BeginPage, EndPage, NumCopies, Orientation, i, strOut, X
    Dim List As ListItem
    CommonDialog1.CancelError = True
    On Error GoTo ErrHandler
   
    CommonDialog1.ShowPrinter
   
    BeginPage = CommonDialog1.FromPage
    EndPage = CommonDialog1.ToPage
    NumCopies = CommonDialog1.Copies
    Orientation = CommonDialog1.Orientation
    For i = 1 To (listview.ListItems.Count)
        Set List = listview.ListItems.Item(i)
        For X = 1 To 5
            strOut = strOut & List.SubItems(X)
        Next
    Next
    For i = 1 To NumCopies
        Printer.Print strOut
    Next
ErrHandler:
    Exit Sub
End Sub
0
 
LVL 1

Expert Comment

by:Benjy
ID: 7078164
0
 
LVL 5

Expert Comment

by:rpai
ID: 7078299
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now