Dynamically populate a drop-down list or list box

You can dynamically populate a drop-down list or list box with values from a data source.

If you have a predetermined and unchanging set of possible values, you can populate a drop-down list or list box when designing the form. See Using drop-down lists and list boxes . If you have a changing set of values, you can dynamically populate a drop-down list or list box from a data source at run time. If you have a long set of values, having it stored in a data source gives the form more flexibility.

For example, you can populate a drop-down list with a list of countries from a data source. Another example is to populate a list box with French product names but have English data values submitted to the data source.

For example, the schema you connect to could have the following defined for a list:

<form> 
      <lists> 
         <item uiname="item1" token="value1"/> 
         <item uiname="item2" token="value2"/> 
      </lists> 
</form>

And the data file you point to could have the following defined for a list:

<form> 
      <lists> 
         <item uiname="MasterCard" token="MC"/> 
         <item uiname="Visa" token="VS"/> 
         <item uiname="Eurocard" token="EC"/> 
         <item uiname="Special Card" token="SC"/> 
      </lists> 
</form>

When you merge the data file with the form design, you would see MasterCard as one of the options in the list, but when the form gets submitted, the token MC is sent to the data source.

If you have an OLEDB data connection, you can use the Data Drop-down List object or the Data List Box object from the Custom category of the Object Library palette to populate a drop-down list or list box with data from a column in a table. See Dynamically populate a drop-down list or list box from an OLEDB data connection .

Before you perform this task, you must ensure the following settings are in effect:

  1. In the Object Library palette, click the Standard category and drag a Drop-Down List or a List Box onto the form design.

    For example, insert a Drop-Down List.

  2. (Optional) In the Object palette, click the Field tab and type a caption for the object in the Caption box.

    For example, type Credit Card .

  3. Do one of the following actions:

    • Click the List Items active label in the Field tab of the Object palette.

    • Click the Specify Item Values active label in the Binding tab of the Object palette.

    Note: For ease of use, both the List Items active label and the Specify Item Values active label display the same Dynamic Properties dialog box.
  4. Select the data connection.

    Note: If you are not already connected to a data source, Default Data Binding is the only selection in the Data Connection list.
  5. Click the triangle beside the Items box and select a binding.

    The binding you select should be a repeating data value or group so that the drop-down list or list box shows more than one item.

    For example, select lists > item.

    The following string appears in the Items box:

    $record.lists.item[*]

    You could type this string into the Items box instead of selecting it.
    Note: For OLEDB data connections, the Items box is not available. Use the Item Text and Item Value boxes to select the database columns to use to populate the list.
  6. To show a user-friendly item name at run time, click the triangle beside the Item Text box and select a binding.

    For example, select @uiname to show MasterCard.

    The data file you point to could have a repeating data value:

    <form> 
          <pymt> 
             <cc type="MC">MasterCard</cc> 
             <cc type="VS">Visa</cc> 
          </pymt> 
    </form>
    Note: If you select #data, the drop-down list shows MasterCard .
  7. (Optional) To save a different value than the Item Text label to the data source, click the triangle beside the Item Value box and select a binding.

    For example, select @token to save MC to the data file.

    The data file you point to could have a repeating data value:

    <form> 
          <pymt> 
             <cc type="MC">MasterCard</cc> 
             <cc type="VS">Visa</cc> 
          </pymt> 
    </form>
    Note: If you select #data, the drop-down list shows MC .
  8. Click OK.

    After a binding has been set, a small link icon appears with the active label.

  9. View the form in the Preview PDF tab.

// Ethnio survey code removed