Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing List Items from a ListView control

Posted on 1998-07-02
7
Medium Priority
?
352 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 80 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
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…
Suggested Courses

715 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