Tutorials > Tutorial 19 - Reusable Layouts |
In True DBList, a layout comprises the complete set of properties that define the appearance and behavior of a list, its splits, and its columns. You can save a list 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 DBList download it asynchronously, an ideal technique for initializing a list 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 ComponentOne server.
Start with the project created in Tutorial 1.
Add three command buttons (Command1, Command2, Command3) to the form (Form1).
Set the Click (Visual Basic) property of Command1, Command2, and Command3 to Retrieve Layout, Save Layout, and Retrieve Layout, respectively. Your form should now look like this.
Right-click TDBList1 to display its context menu.
Choose Properties to display the Property Pages dialog box. Select the Splits tab. Expand the Splits(00) node and set the AllowColMove property to True.
Add the following code to the Click (Visual Basic) event of Command1, Command2 and Command3:
Example Title |
Copy Code
|
---|---|
Private Sub Command1_Click() On Error GoTo Err: ' Load the layout TDBList1.LayoutName = "TestLayout" TDBList1.LayoutFileName = App.Path & "\Tutor19.grx" TDBList1.LoadLayout Exit Sub Err: MsgBox Err.Description End Sub Private Sub Command2_Click() ' Save current layout TDBList1.LayoutFileName = App.Path & "\Tutor19.grx" TDBList1.Layouts.Add "TestLayout" End Sub Private Sub Command3_Click() ' Load layout from ComponentOne TDBList1.LayoutName = "ComponentOne" ' Start the download TDBList1.LayoutUrl = _ "ftp://ftp.componentone.com/pub/files/tutor19.grx" ' Set the order of records (by Country) Data1.RecordSource = _ "Select * From Composer Order By Country" Data1.Refresh End Sub |
Place the following code in the LayoutReady event of TDBList1:
Example Title |
Copy Code
|
---|---|
Private Sub TDBList1_LayoutReady()
' Load layout as soon as it is available
TDBList1.LoadLayout
End Sub
|
Run the program and observe the following:
As in Tutorial 1, True DBList retrieves the database schema information from the Data control and automatically configures itself to display the data for all fields in the database table.
Change the layout of the list by modifying column widths and the row height. You can also rearrange the column order. When you are finished, click the Save Layout button. End the program and then restart it. The list will display the default layout as before. Now, click the Retrieve Layout button. The list will display the layout that you saved previously.
If your computer is connected to the Internet, click the Retrieve ComponentOne Layout button. The list will be configured according to a layout file stored on the ComponentOne server.
For more information, see Reusable Layouts.
This concludes Tutorial 19.