Solved

Printing List Items from a ListView control

Posted on 1998-07-02
7
344 Views
Last Modified: 2010-05-03
How do you print the list items (with Column Headers) from a ListView control?
0
Comment
Question by:UpAllNite
[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
  • 3
7 Comments
 
LVL 9

Expert Comment

by:cymbolic
ID: 1464874
You simply iterate down through the properties, including the column headers and the subitems if multiple columns, prepare your own printlines and print 'em. Wouldn't it be nice if there were a .print method to the listview!  Of course, you can make your own subroutine to do this, passing in only the Listview object as a parameter.  This way you only have to do it once!


0
 

Author Comment

by:UpAllNite
ID: 1464875
Can you provide me with a sample subroutine for a listview called lvwMain with 5 columns?  The total list items would be unknown.
0
 
LVL 7

Accepted Solution

by:
tward earned 20 total points
ID: 1464876
Dim InCounter As Long
Dim OutCounter As Long
 
For OutCounter = 1 To lvwMain.ColumnHeaders.Count
     
     Call MsgBox(lvwMain.ColumnHeaders(OutCounter).Text)
     
Next OutCounter
 
For OutCounter = 1 To lvwMain.ListItems.Count
 
     Call MsgBox(lvwMain.ListItems(OutCounter).Text)
     
     For InCounter = 1 To lvwMain.ColumnHeaders.Count - 1

         Call MsgBox(lvwMain.ListItems(OutCounter).SubItems(InCounter))

     Next InCounter

Next OutCounter

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:UpAllNite
ID: 1464877
Ok, the looping through each column and item works.  But how do I have this information Print to a printer like a report style page?

Such as (See Example Below):

Column1     Column2     Column3   Column4    Column5
-------     -------     -------   -------    -------

Item 1       xxxxxx      xxxxxx    xxxxxx    xxxxxxx
Item 2       xxxxxx      xxxxxx    xxxxxx    xxxxxxx

and so on for each item.......
0
 
LVL 7

Expert Comment

by:tward
ID: 1464878
Just print straight to the printer?

Dim InCounter As Long
Dim OutCounter As Long
  
For OutCounter = 1 To lvwMain.ColumnHeaders.Count
     
     Printer.Print lvwMain.ColumnHeaders(OutCounter).Text; "     ";
     
Next OutCounter
  
For OutCounter = 1 To lvwMain.ListItems.Count
  
     Printer.Print lvwMain.ListItems(OutCounter).Text;
     
     For InCounter = 1 To lvwMain.ColumnHeaders.Count - 1

         Printer.Print lvwMain.ListItems(OutCounter).SubItems(InCounter);

     Next InCounter

Next OutCounter
0
 

Author Comment

by:UpAllNite
ID: 1464879
Ok, it now prints to the printer but everything is in a straight line (columns and items). Also it will only release the print job after I exit the application.

I tried using vbCrLf to break up the lines but to no avail.
0
 
LVL 7

Expert Comment

by:tward
ID: 1464880
If you do:

Printer.Print ""

That will print a blank line or leave the ';' off of the end of a line, that starts a new line.

Printer.EndDoc will end the print job and start it printing just as if you were to exit the application.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using web browser with BING 40 150
MS SQL store procedure to calculate and return result 6 74
fso.FolderExists("\\server\HiddenFolder$") 4 98
vbModal 12 75
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

751 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