Παρασκευή 11 Μαΐου 2012

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. 


  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.

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου