Solved

How can i print ListView report to the printer.

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

11 Experts available now in Live!

Get 1:1 Help Now