Previous Topic

Next Topic

Inhoudsopgave

Book Index

TDBRadioGroup Control

TDBRadioGroup

Description

Represents a group of radio buttons connected to a database.

Remarks

Use TDBRadioGroup to group a set of data-aware radio buttons. Radio buttons that are contained directly in the same control component are said to be "grouped". When a radio button is checked, all other radio buttons in its group become unchecked. Database radio groups provide an easy way to ensure that the user enters one (or at most one) of the options presented for a field. They are also useful for displaying data from fields that have only a few possible values.

To add radio buttons to a TDBRadioGroup, edit the Items property in the Object Inspector. Each string in Items makes a radio button appear in the group box with the string as its caption.

When the user selects a radio button, the "value" of the selected button becomes the contents of the linked field for the current record in the dataset. Specify values for the buttons by editing the Values property in the Object Inspector; the first string in Values corresponds to the first string in Items, and so forth. If no Values strings are set, each button's caption serves as its value.

TDBRadioGroup Properties

Property Property Items: TStringList object (R)

Lists the radio buttons in the radio group. Items holds a TStringList object that lists the captions of the radio buttons in the group. These captions become the "values" of the radio buttons, unless you override them in the Values property; when a button is selected, its value becomes the content of the linked field for the current record in the database.

Property Property Values: TStringList object (R)

Determines the values of the radio buttons. When the user selects a radio button, the "value" of that button is written to the linked field in the database. By default, the value of a button is simply the caption that appears next to it on the screen, as determined by the Items property. In some cases, you may want the values of the radio buttons to differ from their captions. For example, if you use radio buttons to represent a database field whose content can be "Y" or "N", you may want the buttons' captions to be "Yes" and "No". In this case, you would enter "Yes" and "No" in the Items list, and enter "Y" and "N" in the Values list. You can edit the Values list in the Object Inspector, just as you would the Items list. To keep the buttons' captions as their values, leave the Values property empty.

Property Property Columns: Integer (R/W)

Specifies number of columns in the radio group. Columns determines the number of columns in the radio group if Orientation is orVertical (the default), and the number of rows if Orientation is orHorizontal. Its value can range from 1 to 16. The default value is 1, which means that the radio buttons are arranged in a single line.

Property Property ItemIndex: Integer (R/W)

Indicates which radio button in the group is currently selected. ItemIndex holds the index of the selected radio button in the Items list. (The first button is 0.) The value of ItemIndex changes at runtime as the user selects radio buttons. If you want one of the buttons to appear selected when the application starts, assign that button to ItemIndex at design time; otherwise, leave ItemIndex set to the default value of -1, which means that no button is selected.

General Data-Aware Control Properties

Property Property DataField: String (R/W)

Property Property DataSource: TDataSource (R/W)

Property Property ReadOnly: Boolean (R/W)