ComponentOne True DBGrid Pro 8
Tutorial 22 - Reusable Layouts

In True DBGrid, a layout comprises the complete set of properties that define the appearance and behavior of a grid, its splits, and its columns. You can save a grid layout to a binary file, then reuse it in other projects. At design time, you can store multiple layouts in a single file, then load them as needed in code. You can even store a layout file on a remote computer and have True DBGrid download it asynchronously, an ideal technique for initializing a grid on an HTML page.

In this tutorial, you will learn how to save and retrieve layouts at run time. If you have an Internet connection, you can also retrieve a layout file from the APEX server.

  1. Start with the project created in Tutorial 1.

  2. Add three command buttons (Command1, Command2, Command3) to the form (Form1)

  3. Set the Caption property of Command1, Command2, and Command3 to "Retrieve Layout", "Save Layout", and "Retrieve ComponentOne Layout", respectively. Your form should now look like this.

  4. Right-click TDBGrid1 to display its context menu.

  5. Choose Properties to display the Property Pages dialog. Select the Splits tab. Expand the Splits(00) node and set the AllowColMove property to True.

  6. Add the following code to the Click events of Command1, Command2 and Command3:

    Example Title
    Copy Code
    Private Sub Command1_Click()
    
    On Error GoTo Err:
    
        ' Load the layout.
    
        TDBGrid1.LayoutName = "TestLayout"
    
        TDBGrid1.LayoutFileName = App.Path & "\Tutor22.grx"
    
        TDBGrid1.LoadLayout
    
        Exit Sub
    
    Err:
    
        MsgBox Err.Description
    
    End Sub
    
    Private Sub Command2_Click()
    
        ' Save current layout.
    
        TDBGrid1.LayoutFileName = App.Path & "\Tutor22.grx"
    
        TDBGrid1.Layouts.Add "TestLayout"
    
    End Sub
    
    Private Sub Command3_Click()
    
        ' Load layout from APEX.
    
        TDBGrid1.LayoutName = "APEX"
    
     
    
        ' Start the download.
    
        TDBGrid1.LayoutUrl = _
    
            "ftp://ftp.apexsc.com/pub/files/tutor22.grx"
    
     
    
        ' Set the order of records (by Country).
    
        Data1.RecordSource = _
    
            "Select * From Composer Order By Country"
    
        Data1.Refresh
    
    End Sub
    
  7. Place the following code in the LayoutReady event of TDBGrid1:

    Example Title
    Copy Code
    Private Sub TDBGrid1_LayoutReady()
    
        ' Load layout as soon as it is available.
    
        TDBGrid1.LoadLayout
    
    End Sub
    

Run the program and observe the following:

For more information, see Reusable Layouts.

This concludes Tutorial 22.

 

 


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

Product Support Forum  |  Documentation Feedback