public class LinkedDropDownLists
extends Object
Demonstrates one technique that may be used to create linked or dependent
drop down lists. This refers to a situation in which the selection made
in one drop down list affects the options that are displayed in the second
or subsequent drop down list(s). In this example, the value the user selects
from the down list in cell A1 will affect the values displayed in the linked
drop down list in cell B1. For the sake of simplicity, the data for the drop
down lists is included on the same worksheet but this does not have to be the
case; the data could appear on a separate sheet. If this were done, then the
names for the regions would have to be different, they would have to include
the name of the sheet.
There are two keys to this technique. The first is the use of named area or
regions of cells to hold the data for the drop down lists and the second is
making use of the INDIRECT() function to convert a name into the addresses
of the cells it refers to.
Note that whilst this class builds just two linked drop down lists, there is
nothing to prevent more being created. Quite simply, use the value selected
by the user in one drop down list to determine what is shown in another and the
value selected in that drop down list to determine what is shown in a third,
and so on. Also, note that the data for the drop down lists is contained on
contained on the same sheet as the validations themselves. This is done simply
for simplicity and there is nothing to prevent a separate sheet being created
and used to hold the data. If this is done then problems may be encountered
if the sheet is opened with OpenOffice Calc. To prevent these problems, it is
better to include the name of the sheet when calling the setRefersToFormula()
method.