Wednesday, April 4, 2018

Insert a list box

Insert a list box

You can use a list box in a Microsoft Office InfoPath form template to present a list of mutually exclusive choices to a user.

In this article

When to use a list box

The user experience

Insert a list box

Layout tips

When to use a list box

Use a list box when you want to:

  • Enable users to choose a single selection from a list of predefined items.

  • Display values retrieved from a fixed list, from the form template's data source, or from an external data source, such as a database or Microsoft Windows SharePoint Services list.

In the following illustration, users categorize expenses in an expense report form by selecting values in a list box.

Item selected in list box

After you insert a list box on your form template, you must specify the values that you want to appear in it. Otherwise, users will see an empty list when they open a form that is based on your form template. In the List Box Properties dialog box, you can type the entries yourself or configure the list box to retrieve entries from a database or other data source.

Related controls

InfoPath includes controls that are similar to list boxes but that serve different purposes. To decide which of these controls works best on your form template, refer to the following list:

Drop-down list box    Like a list box, a drop-down list box offers users a list of choices. However, in a drop-down list box, the list entries are hidden until the user clicks an arrow next to the list box. If you plan to offer many choices in your list, or if space on your form template is limited, a drop-down list box can be a good choice.

Combo box    Like a list box, a combo box offers users a list of choices. However, in a combo box, the list entries are hidden until the user clicks an arrow next to the combo box. Users can type their own entry into a combo box or choose from a list of predefined entries.

Multiple-selection list box    If you want users to be able to choose more than one item in a list, you can use a multiple-selection list box instead of a list box. In a multiple-selection list box, users indicate a choice by selecting one or more check boxes instead of clicking a value in a list. As with standard list boxes, the entries in a multiple-selection list box are visible when users first open the form.

Option buttons    Like a list box, a group of option buttons enables users to select from a list of mutually exclusive choices. However, with option buttons, users click a small circle to make a choice instead of clicking an item in a list box.

Top of Page

The user experience

List boxes are one of the most commonly used form controls, so most users know how to use them.

To select something from a list box, users simply click the item that they want. The list box is "open," so users can see the list of choices without having to click the control. If the choices in the list exceed the height of the box that contains them, a scroll bar appears on the right side of the control. If users are using the keyboard to fill out the form, they can press the UP ARROW and DOWN ARROW keys to move through the items in the list box.

Top of Page

Insert a list box

The procedure for inserting a list box differs slightly depending on whether you are designing a new, blank form template or basing the design of your form template on a database or other external data source.

The following illustration shows how a list box looks when it is selected in design mode, before a label and entries are added.

List box selected in design mode

Controls can be bound or unbound. When a control is bound, it is connected to a field or group in the data source so that data entered into the control is saved in the underlying form (.xml) file. When a control is unbound, it is not connected to a field or group, and data entered into the control is not saved. When you select or move your pointer over a control, text and a binding icon appear in the upper-right corner of the control. The text indicates the group or field to which the control is bound in the data source. The icon indicates whether the control is correctly bound to that group or field. When the binding is correct, a green icon appears. If there's something wrong with the binding, you'll see a blue or red icon instead.

The data source for the form template consists of fields and groups that appear in a hierarchical view in the Data Source task pane. List boxes are always bound to fields. In the following example, the Category list box on the form template is bound to the category field in the Data Source task pane.

relationship between list box on form template and corresponding field in data source

When you design a new, blank form template, the Automatically create data source check box in the Controls task pane is selected by default. This enables InfoPath to automatically create fields and groups in the data source as you add controls to the form template. These fields and groups are represented by folder and file icons in the Data Source task pane.

If you base the design of your form template on an existing Extensible Markup Language (XML) file, database, or Web service, InfoPath derives the fields and groups in the Data Source task pane from that existing data source.

Insert a list box

  1. On the form template, place the cursor where you want to insert the control.

  2. If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.

  3. In the Controls task pane, do one of the following:

    • To automatically create a field in the data source that is bound to the list box, select the Automatically create data source check box.

    • To bind the list box to an existing field, clear the Automatically create data source check box.

      Note: If the check box is unavailable, the data source is locked. For example, if you base the design of your form template on an XML Schema, you may not be able to add new fields or groups to the data source in InfoPath. This restriction helps to prevent you from inadvertently making changes to the schema that may render it invalid.

  4. Under Insert controls, click List Box.

  5. If you cleared the Automatically create data source check box in step 3, select a field in the List Box Binding dialog box to which you want to bind the list box.

  6. To add a label to the list box, on the form template, type the text above or to the left of the list box, followed by a colon (:).

  7. To specify the values that you want to use as the entries in the list, double-click the list box on your form template.

  8. Click the Data tab.

  9. Do one of the following to populate the list box:

    Type the list box values yourself

    This option is useful when you have a predetermined, limited set of values, and you don't expect those values to change in the future. If the values do happen to change, you must publish an updated version of your form template so that users can see and use the latest list entries.

    1. Click Add.

    2. In the Value box, type the text that you want to store if a user selects this entry.

    3. In the Display name box, type the text that you want to display for this entry, and then click OK.

    4. Repeat steps 1 through 3 for each entry that you want to add to the list box.

    5. To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.

    Use values from another part of the form

    This option is useful when you want the values in your list to change, depending on other values that the users enter into their form.

    1. Under List box entries, click Look up values in the form's data source.

      The entries in the list box must be associated with a particular repeating group or repeating field on your form template.

    2. Click Select XPath Data Source button next to the Entries box, and then in the Select a Field or Group dialog box, click the repeating field or repeating group that contains the fields that will provide the values for the list box, and then click OK.

    3. Click Select XPath Data Source button next to the Value box, click the field that contains the possible values for the items in the list box, and then click OK. One of these values will be saved in the underlying XML when a user clicks an item in the list box.

    4. Click Select XPath Data Source button next to the Display name box, click the field that contains the values that are displayed in the list box, and then click OK.

      Tip: To prevent display name values from appearing multiple times in the list box, select the Show only entries with unique display names check box.

    Use values from a database, Web service, XML document, or SharePoint site

    This option is useful when you want the values in a list box to be up-to-date or refreshed regularly. The values are typically stored in a database or other external data source and are retrieved every time the form is opened.

    1. Click Look up values from an external data source.

    2. Do one of the following:

      • If you already added a data connection, click it in the Data Connection box.

      • To add a new data connection, click Add, and then follow the instructions in the Data Connection Wizard.

        The entries in the list box must be associated with a particular repeating field or repeating group.

    3. Click Select XPath Data Source button next to the Entries box, and then in the Select a Field or Group dialog box, click the group or field that contains the fields that will provide the values for the list box, and then click OK.

    4. Click Select XPath Data Source button next to the Value box, click the field that contains the possible values for the items in the list box, and then click OK. One of these values will be saved in the underlying XML when a user clicks an item in the list box.

    5. Click Select XPath Data Source button next to the Display name box, click the field that contains the values that are displayed in the list box, and then click OK.

      Tip: To prevent display name values from appearing multiple times in the list box, select the Show only entries with unique display names check box.

Top of Page

Layout tips

Use the following tips to help you refine the appearance, size, and other aspects of a list box:

  • Consider widening the list box so that it is a few spaces larger than the average width of the items in the list. That way, the list items aren't partially hidden.

  • To change the width of several list boxes at once, select the list boxes whose size you want to change, press ALT+ENTER, click the Size tab, and then type a new number in the Width box.

  • To change the background color for several list boxes at once, select the list boxes that you want to change. On the Format menu, click Borders and Shading, and then make the necessary adjustments on the Shading tab.

  • To customize the font that appears in a list box, use the Font and Font Size boxes on the Formatting toolbar. To change the font and font size for all of the list boxes on your form template at once, click the list box that contains the formatting that you want, and then on the Format menu, click Apply Font to All List Box Controls.

  • If you want to adjust the spacing between a list box and the objects that surround it on the form template, you can adjust the margin settings in the List Box Properties dialog box (Size tab). Using margins to increase the spacing offers a finer degree of control than using paragraph breaks to increase the spacing.

Top of Page

No comments:

Post a Comment