Customize the Data Display (IBX No Code Tutorial)

From RAD Studio
Jump to: navigation, search

Go Up to Tutorial: Using InterBase Express to Create an Application Without Code

Note that the TDBGrid shown in the previous section displayed metadata and data exactly as it is in the database. In this section, you customize the data's display.

Possible Customizations

The database metadata include field names, such as SPECIES_NO, CATEGORY and COMMON_NAME, and these names are displayed as the headers of the TDBGrid. You might want different names to appear in the application.

You may not want to include all the data fields either. By default, most database fields are displayed in the TDBGrid. Suppose you want to remove the SPECIES_NO column from the TDBGrid.

You customize the data display by specifying which fields you want your application to use. This field list may be a subset of the table's fields. You can also alter how the metadata, such as field name, is displayed by altering entries in the field list.

Creating and Modifying the Field List

To display the Fields Editor, double-click the TIBDataSet component on the Form Designer. Initially, no fields are listed.

  • Right-click the empty list of fields in the Fields Editor. Select Add fields... from the context menu. The Add Fields dialog appears, listing all the fields in the table.
  • If you do not want to use the SPECIES_NO field in this application, CTRL-click the SPECIES_NO field so that it is not included in the selection:
FieldsEdt-InterBaseExpress.png

AddFieldsEdt-InterBaseExpress.png

  • Click OK to accept the list of fields and close the Add Fields dialog. All the fields you selected on the Add Fields dialog are now listed in the Fields Editor.

The Structure View in the upper left of RAD Studio provides a hierarchical overview of the form's components, including the table's fields. In the figure below, note that the Fields list under the "IBDataSet1" node now lists just the fields you added. In addition, the TDBGrid no longer shows the SPECIES_NO field:

StructureView-InterBaseExpress.png


Now that you have created the fields list, you can customize it.

You can change the order of fields in two ways:

  • In the Fields Editor, drag one field name to a new location in the list.
  • In the Structure View, drag one of the fields in the fields list under "IBDataSet1" to a new location in the list.

For instance, drag COMMON_NAME after LENGTH_IN. Note that the order of fields changes in the TDBGrid to reflect the fields list.

You can also change the column headers in the TDBGrid.

  • Select CATEGORY in the Fields Editor. This entry represents a TIBStringField, which inherits from TStringField.
  • In the Object Inspector, change the DisplayLabel property to "Category". Note that when you do this, the column name in the TDBGrid also changes to "Category". See also DisplayLabel.
  • Change the rest of the fields' DisplayLabels to the following new values:


Field Name DisplayLabel

CATEGORY

Category

SPECIES_NAME

Species Name

LENGTH__CM_

Length (cm)

LENGTH_IN

Length (in)

COMMON_NAME

Common Name

NOTES

Notes

GRAPHIC

Graphic

Modifying the TDBGrid list

If you scroll the TDBGrid component all the way to the right, you notice that the Notes and Graphic columns appear. These fields contain data that is not suitable for displaying in a TDBGrid component. The Notes and Graphic fields are already displayed appropriately in other components: the image is displayed in a TDBImage and the memo text in TDBText.

You eliminated the SPECIES_NO field from the TDBGrid by not including the SPECIES_NO field in the fields list. You do not want to remove the NOTES and GRAPHIC fields from the fields list, because then you could not use them in your application at all. You simply want to avoid displaying the NOTES and GRAPHIC columns in the TDBGrid.

To accomplish this, select the NOTES entry in the Fields Editor. In the Object Inspector, change Visible to False. Do the same for the GRAPHIC entry. Now neither of these two fields is displayed in the TDBGrid.

This concludes the construction of the application. You did not have to write a single line of code!

Viewing Database Records at Design Time

When you set the TIBDataSet.Active property to true, you can view database information in the data-aware controls. Only the first record is visible at first. You can also view other database records in a couple of ways:

  • Use the scrollbar of the TDBGrid. As you scroll, line by line, or page by page, different records are displayed.
  • Use the Fields Editor. Note that the Fields Editor dialog has navigation buttons on top. Clicking these control buttons displays the first, previous, next and last database records, respectively.

Previous

Add Visual Components

Next

Run the Application