Autocomplete in VFP9
The textbox class in Visual FoxPro 9 has a new Autocomplete
property which shows the user the previous values that have
been entered in that textbox. Other properties give you
more control over the way that the lookup and autocomplete
will work, but at its simplest all you have to do is to set
the AutoComplete property true to enable the behaviour.
As the user types into the textbox, a list drops down to show
previous entries from that textbox which match the characters
entered so far:
Setting up AutoComplete
There are three properties which control the behaviour of AutoComplete.
All three are on the Data tab of the Properties window:
This can take five values from 0 to 4:
- No autocomplete.
- An alphabetical list.
- With the most frequently-used values first.
- With the most recently-used values first.
- In a user-defined order.
The AutoComplete property is the only one that you need to alter to enable
the basic autocomplete behaviour. A value of 1 is usually the best choice because the
alphabetic order seems to be the easiest for the users to grasp.
As is typical with Microsoft FoxPro, the architecture is open and the
past values are stored in a dbf file. The AutoCompTable
property holds the name of this table. If the table does not
exist then it will be created when the form opens. If you leave
the name blank then VFP will use a table named AutoComp.dbf
in the home directory.
The table is opened when the form opens and closed again when
the form closes but does not appear in the list of work areas.
You can modify the contents of the table with the form on
screen and change the AutoComplete behaviour in real time.
This is the identifying name which will be used to look up
past values for the textbox. If you give no name then VFP
will use the name of the textbox itself. This means that
several textboxes on different forms can share the same list
provided that they all have the same name. It also means
that all textboxes that you've left at the default name of
"Text1" will share the same list.