Solved

Printing List Items from a ListView control

Posted on 1998-07-02
7
333 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
  • 3
  • 3
7 Comments
 
LVL 9

Expert Comment

by:cymbolic
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:UpAllNite
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…

763 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

10 Experts available now in Live!

Get 1:1 Help Now