Create dependent drop-down / list-box in InfoPath using filters

Summary

Suppose you want to have the items listed in a drop-down be dependent on the selection of another drop-down (this is also known as "cascading dropdowns). If you have InfoPath Service Pack 1 installed, you could use the "Filter Data..." feature to accomplish this.

Example

Picture of two drop downs - state and city.

You have one drop down labeled "State: " with the names of states and another drop-down labeled "City: " which gets populated with the names of the cities for the state you selected on the previous drop down.

The city drop-down obtains its values from an xml file which might look something like this:

<Cities>
<City state="Washington">Redmond</City>
<City state="Washington">Seattle</City>
<City state="California">Los Angeles</City>
  <City state="Florida">Orlando</City>
</Cities>

Implementation

  1. In design mode, right click on the "City" drop down and open the Drop-down Properties dialog.
  2. Select to Look up values in a data connection to a database, Web Service, file, Share Point library or list.
  3. Click Add and follow the wizard to add the xml file containing the city data.
  4. After completing Data Connection Wizard, in the Entries field- select the source for the drop-down values by clicking the button on the right of the field. The Select a Field or Group dialog will appear, for this case you will select the "City" repeating group.
  5. Create a Filter by clicking the Filter Data... button and clicking Add... in the Filter Data dialog.
  6. You will want to create a Filter that displays the data in which the "state" attribute is equal to the field corresponding to the "State: " drop-down (Remember that the field value is kept in the form's "Main" data source)

 Additional Notes/Tips  

  • Previous City selection will persist after changing state. You’ll need to set a Rule to change cities to empty after a change is made to states to avoid selected city remaining in City drop down. (Right click the "State" drop-down in design mode and open the Propeties dialog, click the Rules button and create an Action to set the "City" field value to empty, no condition is necessary since this rule will apply when a change is made).
  • Instead of using drop-down controls you could also use list boxes.
  • You could also use Conditional Formatting to disable the "City:" drop-down until a state is selected. 
  • If you'd like to implement dependent dropdowns in a browser-enabled form template, take a look at this article.