InfoPath Basics: List control basics in InfoPath
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.
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:
- 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.
- 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:
- Double-click the list control to open its Properties dialog box.
- 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.
Figure 1. Drop-down list box properties dialog box in InfoPath
For more information, see:
- Insert a drop-down list box
- Insert a list box
- Insert a combo box
- Insert a multiple-selection list box
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:
- 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).
- 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:
