The options that are displayed in a ComboBox, ListBox, NoteBook, or TabBox object.

Property of

ComboBox, ListBox, NoteBook, TabBox

Description

Use the dataSource property to set the options that are displayed in a ComboBox, ListBox, NoteBook, or TabBox object. The dataSource property for a ComboBox or ListBox is a string in one of the following five forms:

ARRAY <array>
creates prompts from elements in an array object.

FIELD <field name>
creates prompts from all the values in a field in a table file.

FILENAME [<filename skeleton>]
creates prompts from file names in the current default directory that match the optional filename skeleton.

STRUCTURE
creates prompts from all the field names in the currently selected table.

TABLES
creates prompts from the names of all tables in the currently selected database. For the default database, this is all the .DBF and .DB files in the current directory.

For a NoteBook or TabBox, only the ARRAY dataSource is allowed. The dataSource string in general is not case-sensitive, except that if you specify a literal array, the array contents will appear as specified.

Adding elements to an array after it has been assigned as a component’s dataSource may not automatically update the component’s options. Files added to the directory after the dataSource property has been set to a file mask will not automatically appear either.

To update the dataSource, you need to reassign the dataSource property. In most cases, you can simply reassert the property by assigning its current value to itself. For example, if you had originally specified all the GIF files in the current directory, the dataSource property assignment would look like this:

with (this.fileCombobox)

dataSource = "FILENAME *.GIF" 

endwith

To update the file list when you press an Update button on your form, the button’s onClick would look like this:

function updateButton_onClick( )

form.fileCombobox.dataSource += "" 

You don’t have to specify what the dataSource string is again, since it’s already contained in the dataSource property. The += operator adds an empty string to reassign the value, which reasserts the dataSource. This makes your code easier to maintain, since the dataSource string is specified in only one place.

When using a FIELD as the datasource string, you can use the fields

value:

form.rowset.fields["myfield"].value

Or a reference to a field object:

form.rowset.fields["myfield"]

When using an array in the dataSource string, you can use a literal array, for example,

array {"Chocolate", "Strawberry", "Vanilla"}

Or you can use a reference to an array object, for example,

array aFlavors

If you use a reference, that array must exist at the time the dataSource property is assigned. Since the dataSource property contains that string (in this example, array aFlavors), if you reassert the dataSource property as shown above, an updated version of the named array must exist. In this example, the array aFlavors must be accessible in the method updateButton_onClick( ).

For this reason, when using an updatable array as the dataSource property, the array is usually created as a property of the form. This makes the array equally accessible from the component that uses the array and from any other component that tries to reassert the dataSource property. In this example, the array aFlavors would be created as a property of the form, and the dataSource string would contain:

array form.aFlavors

The reference form.aFlavors is valid from the event handler of any component on the form.