Sometimes another data source determines which data is valid for a column.
Consider this situation: the Department table includes two columns, Dept_id and Dept_name, listing your company's departments. The Employee table lists your employees. The Department column in the Employee table can have any of the values from the Dept_id column in the Department table.
As new departments are added to your company, you want the DataWindow object containing the Employee table to automatically provide the new departments as choices when users enter values in the Department column.
In situations such as this, you can specify the DropDownDataWindow edit style for a column: it is populated from another DataWindow object. When users go to the column, the contents of the DropDownDataWindow display, showing the latest data.
Figure 21-6: Example of a DropDownDataWindow edit style
In Figure 21-6, a DataWindow object contains a DropDownDataWindow edit style that displays a different DataWindow object containing only the Dept_ID and Dept_Name columns from the Department table. Typically only a single column is displayed in a drop-down DataWindow. The example in the figure displays both columns from the DataWindow because the drop-down width property for the column using the DropDownDataWindow style has been set to more than 100%.
In the following procedure, you create a DataWindow similar to the DataWindow object used in Figure 21-6. You name the DataWindow d_dddw_dept and save it for use in a DropDownDataWindow style. You then create another DataWindow from the Employee table and use the Properties view in the DataWindow painter to associate the Dept_ID column in the new DataWindow with an ad hoc DropDownDataWindow style. The ad hoc style will display the Dept_ID column from the Department table that is used by the d_dddw_dept DataWindow object.
You can also create a named DropDownDataWindow edit style in the Database painter that uses the d_dddw_dept DataWindow object. If you create a named style, and then select it in the DataWindow painter for a column in another DataWindow, properties that you set for the style automatically populate the fields on the Edit page of the Properties view for that column.
For information on creating a named edit style, see “Working with edit styles in the Database painter”.
To use the DropDownDataWindow edit style:
Create a DataWindow object with columns that you want to use in a drop-down list, and save the DataWindow.
You will often choose at least two columns for the DataWindow: one column that contains values that the user sees and another column containing values to be stored in the database. For example, to create the d_dddw_dept DataWindow object, create a tabular DataWindow that contains only the Dept_ID and Dept_Name columns from the Department table in the ASA Sample database.
Select the column for which you want to obtain data from a DataWindow object, click the Edit tab in the Properties view of the DataWindow painter, then select the DropDownDW edit style in the Style Type box.
For example, create a DataWindow from the Employee table, then select the Dept_ID column and specify the DropDownDW edit style for this column.
In the Lines in DropDown box, type the number of rows you want to see in the drop-down DataWindow.
There are five rows in the Dept_ID column, so you
might consider typing 5
for
the number of lines you want to see. You might also consider selecting
the V ScrollBar check box on the Edit tab, so that when you add a
sixth or seventh row, users can scroll to see the entire list of
departments.
In the Width of DropDown (%) box, type 100
to
display the complete width of a single column you select as the
display column.
Click the ellipsis button next to the DataWindow box and select the DataWindow object that contains the data you want to use to populate the drop-down list.
Continuing with the same example, you would select d_dddw_dept. After you select a DataWindow object, two more fields are added to the Edit tab: one for a display column, and the other for a data column.
Figure 21-7: Setting properties for a DropDownDataWindow edit style
In the Display Column box, select the column containing the values that you want to display in the DataWindow object.
In this example, you could choose to display the Dept_Name column, instead of the Dept_ID column, from the drop-down DataWindow d_dddw_dept.
In the Data Column box, select the column containing the values that will be stored in the database.
Here you would probably want the Dept_ID as the data column.
Specify other properties for the edit style and click OK when done.
During execution, when data is retrieved into the DataWindow object, the column whose edit style is DropDownDataWindow will itself be populated. This will occur as data is retrieved into the DataWindow object that is serving as the drop-down DataWindow object.
When the user clicks the down arrow next to the column at runtime, the contents of the drop-down DataWindow object display. When the user selects a display value, the corresponding data value is stored in the DataWindow buffer and is stored in the database when an Update command is issued.