Part III of this series shows you how to use the ListView control in order to display tabular data, then provides a simple tool you can use to print that data.
by Evangelos Petroutsos
April 14, 2004
n the past two 10-Minute Solutions, you've explored the basics of printing with VB6 and built a very simple text editor with print and preview capabilities. Now, learn how to print tabular data from a ListView control. The ListView control is very handy for displaying tabular datathough because it doesn't allow you to edit the data, you need a tool for printing its contents.
The ListView Control Figure 1 shows the test form of this article's sample project, which contains two ListView controls displaying different sets of data, and a preview form for the customer data. The Print and Preview buttons create an instance of the LVPrint class, set a few properties, and then call the PrintList method to preview and print the data. The PrintList method picks up all the information from the corresponding ListView control and generates the printout. The following is the core code behind the Preview buttons:
'Printing the top ListView
Private Sub bttnPreviewCustomers_Click()
Dim LVPRN As New PRNClass.LVPrint
Set LVPRN.LV = ListView1
LVPRN.ReportTitle = "Northwind Customers"
If Not LVPRN.PrintList(True) Then
MsgBox "Preview failed!"
End If
End Sub
'Printing the bottem ListView
Private Sub bttnPreviewInvoice_Click()
Dim LVPRN As New PRNClass.LVPrint
Set LVPRN.LV = ListView2
LVPRN.ReportTitle = "Simple Invoice Printout Demo"
If Not LVPRN.PrintList(True) Then
MsgBox "Preview failed!"
End If
End Sub
Figure 1. The test form for this article's sample project contains two ListView controls displaying different sets of data and a preview form for the customer data.
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!