次の方法で共有


Controlling Display of a Field

Additional properties for fields allow you to control how a field and its values appear on forms, Browse windows, and reports. You can specify a display format, a default field caption, and a default class and class library.

Defining a Format

A format provides an output mask that determines the manner in which the value of a field is displayed in a form, Browse window, or report. For example:

To provide a format

  • In the Table Designer, enter the mask in the Format box in the Display area.

    -or-

  • Use the DBSETPROP( ) function to set the Format property.

For example, the following code specifies a display format for a postal code:

DBSetProp("orders.postalcode","field","Format","@R 99999-9999")

Creating Captions for Fields

You can create a caption for each field in a database table. Visual FoxPro displays a field's caption text as the column header in a Browse window and as the default header name in a form grid.

To add a caption to a field in a database table

  • In the Table Designer, enter the text for your caption in the Caption box in the Display area.

    -or-

  1. Select the table in the Database Designer and choose Modify.

  2. Select the field you want to assign the caption to.

  3. In the Caption box, type the caption you want displayed for the field.

  4. Choose OK.

    -or-

For example, you might want to create a caption for the fax field in your supplier table by entering "Supplier_Fax" as the caption for the field:

?DBSETPROP('supplier.fax', 'field', 'caption', 'Supplier_Fax')

For more information on using DBSETPROP( ) to set properties on database table fields, see Creating Databases.

Setting a Default Class

To save time later when you're creating forms, you can set a default class for a field. Once set, each time you add the field to a form, the control on the form uses the class you specify as the default. For example, character fields automatically appear as text box controls when you add them to a form. If you want to automatically create a combo box control instead when you use the field in a form, you can set that class as the default for this field. You can also use class libraries that you've created.

To set a default class

  • In the Table Designer, choose a class and library in the Default Class box and the Default Library box.

If you find you're often changing the library and class for your fields, you can map the fields data types to a library and class in the Options dialog box. For more information about mapping your field data types to classes, see Configuring Visual FoxPro. For more information about creating classes, see Object-Oriented Programming.

See Also

Creating Default Field Values | Enforcing Business Rules | Working with Tables | Naming Fields | Creating Default Field Values | Table Designer, | DBSETPROP( ) | Restricting Access to Fields