InfoPath Basics: List control basics in InfoPath

Applies to: InfoPath 2007

This article explains how to use list controls such as drop-down list boxes, combo boxes, list boxes, and multi-select list boxes in InfoPath.

ADVERTISEMENTS

Introduction to list controls

List controls are used in InfoPath to be able to present a list of options to the user. The following list controls are available for non-browser-compatible form templates:

  • Drop-down list box
  • Combo box
  • List box
  • Multiple-selection list box

And the following list controls are available for browser-compatible form templates:

  • Drop-down list box
  • List box

All list controls have 2 things in common:

  1. To add items to a list you must either bind the control to a repeating node in the Main data source or to a repeating node in a secondary data source or manually enter the items for the list.
  2. To retrieve the value of the selected item you must retrieve the value of the field on the InfoPath form that represents the list control. Note: A list control item has a value and a display name. When you select an item from a list, you are selecting the value of the item and not the display name of the item.

How to add items to a list control

To add items to a list control, you must either bind the list control to a data source or manually enter the items.

To add items to a list control:

  1. Double-click the list control to open its Properties dialog box.
  2. On the List Properties dialog box, under the List box entries section, select either Enter list box entries manually, Look up values in the form's data source, or Look up values from an external data source.
    Drop-down list box properties dialog box in InfoPath
    Figure 1. Drop-down list box properties dialog box in InfoPath

When should you use which method to add items to a list?

Enter list box entries manually

Use Enter list box entries manually, if you want a quick and easy way of adding items to a list and if you do not have to look up the display names of items.

  • Advantages: Quick and easy method to add data to a list and the data is stored within the InfoPath form template itself.
  • Disadvantages: You cannot perform actions on the list data. For example, you will not be able to look up data in the list.

Look up values in the form's data source

Use Look up values in the form's data source, if you want to store the items from the list along with the other data in the InfoPath form itself and not in a data source that resides outside of the form.

  • Advantages: The list data is always available in the InfoPath form itself and there is no dependency on external connections being available to retrieve data.
  • Disadvantages: The XML of the InfoPath form can become large especially if a list contains many items and/or you are using many lists on the InfoPath form.

Look up values from an external data source

Use Look up values from an external data source, if you do not want to store the items from the list along with the other data in the InfoPath form itself.

  • Advantages: The list data is stored outside of the InfoPath form, so the XML of the InfoPath form will not become large due to many and/or long lists.
  • Disadvantages: External connections to retrieve list data can become unavailable at times (e.g. network connections), which will prevent you from being able to retrieve data. And you will have to re-query the external data source whenever the form is (re-)opened.

How to programmatically add items to a list control

To programmatically add items to a list control, you must:

  1. Bind the list control to a data source (either a repeating node in the Main data source of the InfoPath form or a repeating node in an external data source).
  2. Write code that will programmatically add items to the repeating node of the data source that the list control is bound to.

How to retrieve the value of the selected item in a list

When you drag-and-drop a list control onto an InfoPath form template, a field is added to the InfoPath form template. The value of this field represents the value of the selected item in the list.

To retrieve the value of the selected item in a list, you must retrieve the value of the field on the InfoPath form template that represents the list. You can retrieve the value of field by using a rule or you can retrieve the value of a field by using code.

How to retrieve the display name of the selected item in a list

To retrieve the display name of the selected item in a list, you will have to perform what is known in Excel as a VLOOKUP, that is, you will have to look up the display name of the item in the data source that the list is bound to the (secondary) data source by filtering the data source on the value of the selected item in the list.

Note: You cannot retrieve the display name or the selected item if you have manually entered the list items. This method can only be used if you have bound the list to a data source (Main or secondary data source).

 


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