How to Display Only Selected Fields in the DbGrid Component

See how use the Fields Editor to define a list of some of the fields in a table that are to be displayed in the Grid. Even more: see how to specify the field order.

Start Delphi and select File | New Application…
In order to use this how to we need the form from one of the How Tos named: ‘How To Create a Simple Database Display Form’ (see: Related Features)
Open the Fields Editor by double-clicking the TTable component. By default, the list of fields is empty (all the fields are displayed)
Click Add to open a dialog box listing the fields in the Customer table. By default, all fields are selected.
Click CustNo to select it, then control-click to select the Company, Phone, and LastInvoiceDate fields.
Click OK to confirm your choices and close the dialog box.
In the form, the grid changes: instead of displaying all fields, it displays only the fields you selected.
Use the Fields Editor to change the field order as follows: Click LastInvoiceDate in the list of fields, then drag it to the third place in the list, between Company and Phone.
In the form, the grid changes to display columns in their new order.
Close the Fields Editor by choosing Close from the Control menu.
Press F9 to run the project.
Browse through the records.

By choosing fields in the Field Editor, we can tell a TTable component which fields to make available to the components that are linked to it.
For each field, delphi creates a corresponding TField component. TField components are invisible components that provide access to field values and display attributes.