Solved

How can i print ListView report to the printer.

Posted on 2002-06-13
3
4,548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses
Course of the Month4 days, 13 hours left to enroll

636 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