Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

Printing List Items from a ListView control

How do you print the list items (with Column Headers) from a ListView control?
0
UpAllNite
Asked:
UpAllNite
  • 3
  • 3
1 Solution
 
cymbolicCommented:
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
 
UpAllNiteAuthor Commented:
Can you provide me with a sample subroutine for a listview called lvwMain with 5 columns?  The total list items would be unknown.
0
 
twardCommented:
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!

 
UpAllNiteAuthor Commented:
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
 
twardCommented:
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
 
UpAllNiteAuthor Commented:
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
 
twardCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now