Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

How to Display Only Selected Fields in the DbGrid Component
From your Delphi Programming Guide

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.

Difficulty Level: Average    Time Required: 10 minutes


Here's How:
  1. Start Delphi and select File | New Application...
  2. 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)
  3. Open the Fields Editor by double-clicking the TTable component. By default, the list of fields is empty (all the fields are displayed)
  4. Click Add to open a dialog box listing the fields in the Customer table. By default, all fields are selected.
  5. Click CustNo to select it, then control-click to select the Company, Phone, and LastInvoiceDate fields.
  6. Click OK to confirm your choices and close the dialog box.
  7. In the form, the grid changes: instead of displaying all fields, it displays only the fields you selected.
  8. 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.
  9. In the form, the grid changes to display columns in their new order.
  10. Close the Fields Editor by choosing Close from the Control menu.
  11. Press F9 to run the project.
  12. Browse through the records.


Tips:

  1. 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.
  2. For each field, delphi creates a corresponding TField component. TField components are invisible components that provide access to field values and display attributes.

Related Information:




More How To's from your Guide to Delphi Programming


Put this How To on your PDA!




Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.