Display the first item in a drop-down list box in 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.
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.
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.
To automatically select and display the first item in a drop-down list box in InfoPath 2010:
- In InfoPath 2010, create a new Blank Form template.
- Add a data connection to a SharePoint list. Here we will use a SharePoint list called OfficeApplications.
- Add a Drop-Down List Box control to the form template and populate it with the items from the SharePoint list.
- Set the Default Value of the drop-down list box to the following formula:
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  has been manually added to the XPath expression to be able to retrieve the first item from the SharePoint list.
- Save and publish the form template.
- 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.
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 of S.Y.M. Wong-A-Ton. 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, S.Y.M. Wong-A-Ton.
Related InfoPath Articles:
- Add a data connection to a SharePoint list in InfoPath 2010
- Main vs. secondary data sources
- Cascading drop-down lists with a repeating table using SharePoint lists
- Dependent drop down lists with disappearing items
- Use a SharePoint list for a shrinking list in an InfoPath repeating table