Using the combo box in vb6

Insert a combo box

A combo box is a text box with a list box attached. This type of control allows users to select a predefined value from a list or enter their own value in the control's text box. The list is hidden until the user clicks the arrow next to the field.

Content of this article

Uses for a combo box

Use a combo box to:

  • Allow users to select a predefined value from a list of choices or enter their own value

  • Default hiding of elements in the form

  • Display values ​​obtained from a fixed list, from the data source of the form template, or from an external data source, e.g. A database or Microsoft Windows SharePoint Services list

In the illustration below, users categorize expenses on an expense report form by selecting values ​​from a combo box. If the required value is not displayed, you can enter it in the field instead of selecting a value from the list. In this example, the user is typing the words Telephone fax a.

After you've added a combo box to your form template, you need to specify the values ​​that you want to be displayed. Otherwise, the user will see an empty list when they click the arrow next to the combo box. In the dialog box Combo Box Properties you can enter the entries yourself or configure the combo box to retrieve entries from a database or other data source.

Related controls

Microsoft Office InfoPath includes other controls that are similar to combo boxes but serve different purposes. To decide which of these controls will work best on your form template, use the following list:

List box : Similar to a combo box, a list box allows users to select values ​​from a list. However, users cannot add their own values ​​to a list box. Also, a list box shows all of the items in the list, while the items in a combo box are hidden until the user clicks the control. If you intend to give the user many choices in your control, list boxes may take up too much space on your form template. In this situation, a drop-down list box or combo box might be a better choice.

Drop-down list box : Similar to a combo box, a drop-down list box allows users to select a value from a list that is hidden by default on the form. However, a drop-down list box does not allow users to add items to the list as they do a combo box.

List field for multiple selection : If you want to allow users to select more than one item from a list, you can use a multiple selection list box. Multi-selection list boxes look like two or more check boxes in a scrollable list. Similar to a combo box, a multiple list box allows users to add their own item to the list.

Radio buttons : Similar to a combo box, a group of radio buttons allows users to choose from a list of mutually exclusive choices. With radio buttons, however, users click a small circle to make a selection rather than an item in a list box.

Top of page

The ease of use

Combo boxes look similar to drop-down list boxes, but allow users to add their own item to the list if needed. If you have your own list items in the dialog box when you create a combo box Combo Box Properties manually, InfoPath displays "Select or Enter" as the default entry in the combo box. This way, users learn that both actions are possible. If the list items in the combo box display values ​​from elsewhere on the form or from a secondary data source, the text "Select or Enter" is omitted.

When users first open a form, the list items in a combo box are hidden. To open the list, users first click an arrow to the right of the combo box. They can then click on an element to select it.

If no corresponding list item is displayed, you can click in the field and enter your own value.

Top of page

Compatibility Considerations

When designing a form template in InfoPath, you can choose to design a browser-compatible form template. When designing a browser-compatible form template, the task pane Controls combo box controls are not available because they cannot be viewed in a web browser.

Top of page

Insert a combo box

The procedure for inserting a combo box differs slightly depending on whether you are designing a new, blank form template or whether you are designing your form template based on a database or some other external data source.

The following illustration shows what a combo box looks like when selected in Design mode.

Controls can be bound or unbound. When a control is bound, it is linked to a field or group in the data source, so data entered into the control is stored in the underlying form (XML) file. When a control is unbound, it is not linked to a field or group, and data entered into the control is not saved. When you select or hover over a control, text and a binding icon appear in the upper-right corner of the control. The text indicates the group or field that the control is linked to in the data source. The symbol shows whether the control is correctly bound to this group or the field. A green icon will appear when the binding is correct. If there is something wrong with the binding, a blue or red icon will appear instead.

The data source for the form template consists of fields and groups that are in the task pane Data Source can be displayed in a hierarchical view. Combo boxes are always tied to fields. In the example below is the combo box category in the form template in the task area Data Source to the field category bound.

If you're designing a new, blank form template, the check box is out Create data source automatically in the area of ​​responsibility Controls enabled by default. This allows InfoPath to automatically create fields and groups in the data source when you add controls to the form template. These fields and groups are in the task pane Data Source represented by folder and file symbols.

When you design your form template based on an existing Extensible Markup Language (XML) file, database, or web service, InfoPath routes the fields and groups in the task pane Data Source from this existing data source.

Insert a combo box

  1. Place the cursor on the form template where you want to insert the control.

  2. If the job Controls does not appear, click the menu Insert on More controls, or press ALT + I, C.

  3. Run in the task pane Controls do one of the following:

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

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

      Note: If the check box is not available, the data source is locked. For example, if you are designing your form template based on an XML schema, you may not be able to add new fields or groups to the data source in InfoPath. This restriction helps prevent you from inadvertently making changes to the schema that would invalidate it.

  4. Click below Insert controls on Combo box.

  5. If you check the box Create data source automatically disabled in step 3, select in the dialog box Combo box binding select the field to which the list field is to be bound.

  6. To add a label to the control, enter text above or to the left of the control followed by a colon (:).

  7. To specify the values ​​that you want to use as entries in the list, double-click the combo box.

  8. Click the tab Data.

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

    Manually entering your own list field values

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

    1. click on Add.

    2. Enter in the field value the text to be saved when a user selects this entry.

    3. Enter in the field display name type the text that you want to appear 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 on the toolbar default on preview, 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 based on other values ​​that the user enters into the form.

    1. Click below List box entries on Look up values ​​in the form's data source.

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

    2. Click next to the field Entries on Select XPath , and then click in the dialog box Select field or group click the repeating field or group that contains the fields that you want to provide the values ​​for the list box, and then click OK.

    3. Click next to the field value on Select XPath , then click the field that contains the possible values ​​for the items in the list box, and finally click OK. One of these values ​​is stored in the underlying XML when a user clicks an item in the list box.

    4. Click next to the field display name on Select XPath , then click the field that contains the values ​​that appear in the list box, and finally click OK.

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

    Use values ​​from a database, web service, XML document, or SharePoint website

    This option is useful when you want the values ​​in a list box to be current or to update them regularly. Typically, the values ​​are stored in a database or other external data source and retrieved each time the form is opened.

    1. click on Look up values ​​in external data source.

    2. Do one of the following:

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

      • To add a new data connection, click on Add, and then follow the instructions in the data connection wizard.

        The entries in the list box must be assigned to a specific repeating field or a specific repeating group.

    3. Click next to the field Entries on Select XPath , and then click in the dialog box Select field or group click the group or field that contains the fields that you want to provide the values ​​for the list box, and then click OK.

    4. Click next to the field value on Select XPath , then click the field that contains the possible values ​​for the items in the list box, and finally click OK. One of these values ​​is stored in the underlying XML when a user clicks an item in the list box.

    5. Click next to the field display name on Select XPath , then click the field that contains the values ​​that appear in the list box, and finally click OK.

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

Top of page

Layout tips

The following tips are designed to help you optimize the look, size, and other aspects of a combo box control:

  • Consider making the combo box wider so it's a few spaces wider than the average width of the items in the list. This way the list items are not partially hidden.

  • To change the width of multiple combo boxes at once, select the boxes you want to resize, press ALT + ENTER, click the tab size, and then type in the box width a new number.

  • To change the background color for multiple combo boxes at once, select the boxes that you want to change. Do you click in the menu format on Frame and shading, and make the necessary adjustments on the tab shading in front.

  • To customize the font used in a combo box, use the fields font and Font size on the format toolbar. To change the font and size for all combo boxes in your style at once, click the box that contains the formatting you want. Then click in the menu format on Use the font for all controls of the type "Combo Box".

  • If you want to adjust the distance between a combo box and the objects surrounding it in the style, you can change the margin settings in the dialog box Combo Box Properties (Tab size) to adjust. Using margins to increase the spacing gives you more granular control than using paragraph breaks to increase the spacing.

Top of page