Display the first item in a drop-down list box in InfoPath 2010

Applies to: InfoPath 2010

Learn how you can use an XPath filter expression to set a drop-down list box that is being populated by a SharePoint 2010 list to automatically select and display its first item.

ADVERTISEMENTS

Problem

You have a drop-down list box that is being populated with items from a secondary data source such as a SharePoint list. You want to have the first item in the drop-down list box automatically selected when the form is opened.

Solution

You can use an XPath filter expression to set the value of the drop-down list box to be equal to the value of the first item in the secondary data source.

Discussion

To automatically select and display the first item in a drop-down list box in InfoPath 2010:

  1. In InfoPath 2010, create a new Blank Form template.
  2. Add a data connection to a SharePoint list. Here we will use a SharePoint list called OfficeApplications.
  3. Add a Drop-Down List Box control to the form template and populate it with the items from the SharePoint list.
  4. Set the Default Value of the drop-down list box to the following formula:

    xdXDocument:GetDOM("OfficeApplications")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[1]/d:Title

    Here, OfficeApplications is the secondary data source linked to the SharePoint list, d:SharePointListItem_RW is the repeating group in the secondary data source, and d:Title is the field being used to display items in the drop-down list box. Here the filter [1] has been manually added to the XPath expression to be able to retrieve the first item from the SharePoint list.
  5. Save and publish the form template.
  6. Test the form.

When you open the InfoPath form, the first item from the SharePoint list should be automatically displayed as the currently selected item in the drop-down list box.

 


Related InfoPath Articles:

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services