Tutorials > Tutorial 20 - Printing, Print Preview, and Export |
In this tutorial, you will learn how to use the printing and exporting capabilities of True DBList.
Start with the project created in Tutorial 1.
Add two command buttons (Command1 and Command2) and a check box (Check1) to the form (Form1).
Set the Click (Visual Basic) property of Command1, Command2, and Check1 to Print Preview, Export HTML, and Export Selected Rows, respectively. Your form should now look like this:
If you wish to select more than one row, you must also change the MultiSelect property (from the Properties window or the General tab on the Properties Pages dialog box) from the default 0 - None to 2 - Extended. |
Enter the following code in the Form_Load (Visual Basic) event:
Example Title |
Copy Code
|
---|---|
Private Sub Form_Load() ' Initialize the Data control Data1.Refresh ' Allow user to change the column order TDBList1.AllowColMove = True ' Change the presentation of the list With TDBList1.Columns .Item("Country").BackColor = vbCyan .Item("Country").Font.Name = "Times New Roman" .Item("Last").NumberFormat = ">" .Item("Last").ForeColor = vbRed End With With TDBList1.HeadingStyle .Font.Bold = True .BackColor = vbBlue .ForeColor = vbYellow End With End Sub |
Add the following code to Command1 and Command2:
Example Title |
Copy Code
|
---|---|
Private Sub Command1_Click() With TDBList1.PrintInfo ' Set the page header .PageHeaderFont.Italic = True .PageHeader = "Composers table" ' Column headers will be on every page .RepeatColumnHeaders = True ' Display page numbers (centered) .PageFooter = "\tPage: \p" ' Invoke Print Preview .PrintPreview End With End Sub Private Sub Command2_Click() ' Depending on the Check1.Value ' the list will export all or just selected rows TDBList1.ExportToFile App.Path & _ "\Tutor20.html", False, Check1.Value End Sub |
Run the program and observe the following:
True DBList displays the data using the font and color changes specified in step 4.
Click the Print Preview button to display a separate application window similar to the following. Note that the output mirrors the format of the list.
Press the PgDn key to view the next page of records. Note that this page also contains column headers because the RepeatColumnHeaders property was set to True in code.
Experiment with the View menu commands and the zoom factor combo box to preview the output at different resolutions. When you are finished, close the preview window.
Click the Export HTML button to create a file named TUTOR20.HTML in the TUTOR20 directory. Load this file into your browser and note that the generated HTML table mirrors the format of the list.
Go back to Form1 and select one or more records in the list. Check the box labeled Export Selected Rows, and then click the Export HTML button. Refresh your browser, and note that only the selected rows appear in the table.