Solved

Printing List Items from a ListView control

Posted on 1998-07-02
7
336 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now