Solved

How can i print ListView report to the printer.

Posted on 2002-06-13
3
4,447 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 48
Sorting multiple rows and columns, and count duplicates in Excel 2013 4 92
MsgBox 4 71
IF ELSE Statement in Excel Macro VBA 16 87
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

680 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