Working with Drop-Down Lists and List Boxes


While text boxes provide an easy method of entering data on a form, the consistency of data entered can sometimes be a problem. InfoPath provides a robust set of tools for validating user input, but for commonly entered data (for example, States, Countries, Product Codes, and so on) it may be easier to use a drop-down list to enter data instead of a simple text box.

A drop-down list or list box, like the ones shown in Figure 6-9, can be used to present the user with a number of choices that appear in a list. When using a drop-down list, these choices appear when the down arrow to the right of the field is clicked, and when using a list box, these items appear by default.

click to expand
Figure 6-9: A drop-down list and list box on a form

Users can then select an item from the list without having to retype the data. This helps to eliminate inconsistent data and limits the choices a user has for data entry for a particular field.

Drop-down lists and list boxes can work in either of two ways. If you know which items you would like to appear in the list and those items are not stored in an existing database or other data source, you can enter those items manually. If you do have those items stored in an existing database, you can hook directly into that data source to populate your drop-down list. The following sections look at both of these methods.

Creating List Box Entries Manually

To create the list box entries manually, first add a drop-down list or list box to your form. Then, right-click the drop-down list or list box and select Properties to open the dialog box shown in Figure 6-10.

click to expand
Figure 6-10: Drop-down and list box options

The option Enter List Box Entries Manually is selected by default—to add a new entry, click the Add button to open the dialog box shown here.

Enter a value and a display name for this item—the user will see the display name in the list, but the actual value is what will be passed back to the database or XML file when the form is submitted or saved. Click OK to return to the Data property page.

You can use the Modify and Remove buttons to modify or delete any entries you may have created, and you can use the Move Up and Move Down buttons to change the order in which your items appear in the list. Finally, to choose the value that is initially selected, highlight an item and use the Set Default button to make it the default value to be used.

When you are finished, click OK to accept your changes to the item list and property pages and return to your form. You should now be able to preview the form and view the items you have created in your drop-down list or list box and the display names you have created.

Looking Up List Box Entries

While manually creating the list box entries can be the easiest way to quickly get a new form up and running, it is a better practice to store list information in a database or other data source. This enables you to reuse these items in multiple forms without having to re-create them each time, and as new items are added to the database, they will automatically appear in the list.

To look up list box entries, you need to create a secondary data source that will be used to look up values in an external database or data source. To do this, add a drop-down list or list box to your form, right-click it, and select Properties. Click the Data property page and select the option Look Up in a Database, Web Service, or File, which changes the dialog box to look like the one shown in Figure 6-11.

click to expand
Figure 6-11: List box options

To create a link to the data source where your list box entries reside, click the Secondary Data Source button to show a list of secondary data sources already associated with your form—if you don’t see the data source you wish to use in the list, click the Add button to open the Data Source Setup Wizard. Following the same steps covered in Chapter 5, select the type of data source (XML Data File, Database, Web Service) and walk through the wizard to select where the data item resides.

Note

If you are using a data source that is not in the list, you may need to consider writing an XML Web Service as a “wrapper” to connect to your data source or consider using SQL Server or Access as an intermediate database format.

After you have set up your data source, you will be returned to the list of secondary data sources available for your form—click the Close button to return to the Data property page of your drop-down list or list box. You should now be able to see your secondary data source in the Data Source drop-down list, as shown in Figure 6-12.

click to expand
Figure 6-12: List box options with the secondary data sources showing

In order to look up the list box items from your data source, you need to specify the field or group that you want to use for the Entries field in your drop-down list or list box. Click the icon beside the Entries field to open the standard InfoPath field picker dialog box, shown in Figure 6-13, and select the field where the data for your list resides.


Figure 6-13: Selecting a group or field

When you are finished selecting your field, click OK to return to the Data property page—your selection will be translated into an XPath reference and should now be displayed in the Entries text box. If your secondary data source had two fields that were used and grouped together (for example, a state abbreviation field and the full description, like CA and California), you could have selected this grouping and then used the icons beside the Value and Display Name settings to match the name that would be displayed in your list to the actual value that would get passed back to the underlying data source or XML file when your form was submitted or saved.

Tip

As it is, by selecting one entry, both the value and the display name are the same. Regardless of which one the user selects from the list the same value will be returned to the data source or XML file.

Keep in mind that when looking up a value to display in a drop-down list or list box that InfoPath submits a simple SELECT query against the data source. From the earlier example in which you were selecting from a State field, you would get multiple values for each state in the list (for example, CA, CA, CA). To eliminate these duplicate values, either use a lookup table specifically created for the purpose that only contains one of each item or change the SQL query in your secondary data source to SELECT DISTINCT to eliminate duplicate records.

start sidebar
How to...—Work with the Date Picker

Another handy object for data entry is the Date Picker, shown in the following illustration, which can be used to select dates using a calendar instead of actually entering the entire date by hand.

A Date Picker object looks similar to a Text Box object, but features a small calendar icon on the right side of the field. Clicking this icon causes a small calendar to pop up that allows you to navigate through the calendar and select a date.

The Date Picker control can be added to your control in the same way you add the other data entry objects you have looked at so far, by dragging and dropping it from your data source or from the Controls view of the Task Pane.

There aren't a lot of properties associated with this object, because its use is pretty straightforward—the calendar that appears when the icon is clicked defaults to the current month, and the current date is highlighted with a red outline. You can use the right and left arrows at the top of the calendar to navigate through the months of the year, and then click to select the date you want. This date in turn is displayed in the associated text box, and its value is passed back to the underlying data source or XML file.

end sidebar




How to Do Everything with Microsoft Office InfoPath 2003
How to Do Everything with Microsoft Office InfoPath 2003 (How to Do Everything)
ISBN: 0072231270
EAN: 2147483647
Year: 2006
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net