Welcome to MSDN Blogs Sign in | Join | Help

InfoPath Team Blog

Tips and tricks to get the most out of Microsoft InfoPath

News

  • For questions, comments, and feedback please use the public newsgroup: microsoft.public.infopath
    This is provided "AS IS" with no warranties, and confers no rights. Use of included script samples and forms are subject to the terms specified in the Terms of Use.
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.
Posted: Wednesday, March 24, 2004 1:58 PM by infopath
Filed under:

Comments

Tom said:

Is there a way to accomplish this without SP1?
# March 24, 2004 2:17 PM

Amanda Murphy's Weblog XBOX :: Technology :: Busin said:

From Lauraj's blog, I just read that the Infopath team has a blog. Great news. I didn't realize but then again I haven't been doing much blog related reading (or writing for that matter) for the past couple of weeks so I think it's time to catch up. Today's post is on one of my fave new things from the SP1 preview. Using filters on your dropdown boxes and secondary data sources....
# March 24, 2004 9:03 PM

Luigi said:

I battled bravely with this for a while before cracking it with a secondary data source I created from an access database but when I tried to hook it up to the SQL server I lost the dependent dropdown values.

The connection works fine with both dropdowns populated with the full lists until I try to build the filter, then the dependent dropdown drops out.

Any ideas

Cheers

Luigi
# March 24, 2004 7:10 PM

InfoPath Team said:

To do this without SP1: lets say you have a query for the data adapter that you want to update based on the selection of another drop-down. What you want to do is write script such that on the change of the primary drop down, you update the query for the adapter you want to refill itself and then requery that adapter.
# April 13, 2004 12:05 PM

James said:

I have a dependent drop-downs/list-box in InfoPath using Filters working in a repeating table for the first row; however, the subsequent rows contain any previously filtered data.

I am sure there is a simple way to fix it. I am just over looking it.
# May 25, 2004 7:13 AM

Shirley said:

I also have the above problem.
# May 26, 2004 1:45 AM

infopath said:

For the two above comments: in InfoPath 2003, you need to employ an XPath current() function, described in this article:

http://blogs.msdn.com/infopath/archive/2004/09/13/228881.aspx

InfoPath 2007 will do this for you.

Thanks,

- Alex

# October 15, 2006 8:04 PM
Anonymous comments are disabled
Page view tracker