ComponentOne True DBGrid Pro 8
Tutorial 23 - Printing, Print Preview, and Export

In this tutorial, you will learn how to use the printing and exporting capabilities of True DBGrid.

  1. Start with the project created in Tutorial 1.

  2. Add two command buttons (Command1 and Command2) and a check box (Check1) to the form (Form1)

  3. Set the Caption property of Command1, Command2, and Check1 to "Print Preview", "Export HTML", and "Export Selected Rows", respectively. Your form should now look like this:

  4. Enter the following code in the Form_Load event:

    Example Title
    Copy Code
    Private Sub Form_Load()
        ' Initialize the Data control.
        ' Allow user to change the column order.
        TDBGrid1.AllowColMove = True
        ' Change the presentation of the grid.
        With TDBGrid1.Columns
            .Item("Country").BackColor = vbCyan
            .Item("Country").Font.Name = "Times New Roman"
            .Item("Last").NumberFormat = ">"
            .Item("Last").ForeColor = vbRed
        End With
        With TDBGrid1.HeadingStyle
            .Font.Bold = True
            .BackColor = vbBlue
            .ForeColor = vbYellow
        End With
    End Sub
  5. Add the following code to the Click events of Command1 and Command2:

    Example Title
    Copy Code
    Private Sub Command1_Click()
        With TDBGrid1.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.
        End With
    End Sub
    Private Sub Command2_Click()
        ' Depending on the Check1.Value the grid will export all or just selected rows.
        TDBGrid1.ExportToFile App.Path & _
                    "\Tutor23.html", False, Check1.Value
    End Sub

Run the program and observe the following:



Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback