Insert a section
You can use a section to organize groups of related controls on a Microsoft Office InfoPath form template.
In this article
When to use a section
Use a section when you want to organize a set of related controls on your form template. For example, on an insurance claim form template, you might use a section to group a set of text boxes that are used to collect contact information from policyholders.
You can also use conditional formatting to show or hide sections that are based on values that users enter elsewhere in the form. For example, on an expense report form, you might use conditional formatting to show a Manager approval section to users when their expenses total more than $1,000. If expenses are less than that, the section remains hidden on the form.
When you insert a section onto your form template, you are essentially inserting an empty container. For the section to be useful, you must insert other controls inside it. These controls might include text boxes, list boxes, or even other sections.
Tip: By default, section borders are invisible on the form. If you want an outline to appear around your section that is similar to the one shown on the insurance claim example, you can apply a border to the section in the Borders and Shading dialog box.
Related controls
InfoPath includes other controls that are similar to sections but that serve different purposes. To decide which of these controls works best on your form template, refer to the following list:
Repeating section To create a section that users can insert onto a form multiple times, use a repeating section or another repeating control.
Optional section If you add a section to your form template, it will appear on the form when a user first opens it. Optional sections, on the other hand, are hidden by default. Users can choose whether to insert the optional section on their form.
Choice group To insert a section that can be replaced with another section, use a choice group. A choice group contains two or more sections. By default, one of these sections appears on the form. Users can choose to replace it with a different section.
Insert a section
The procedure for inserting a section 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 section looks 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. Sections are always bound to groups in the form template's data source. Each control in a section is bound to a field that is part of the section's group.
In the following example, the Policyholder Information section on the form template is bound to the addressPolicyholder group in the Data Source task pane.
Insert a section on a new, blank form template
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.
-
On the form template, place the cursor where you want to insert the control.
-
If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.
-
Under Insert controls, click Section.
-
To add controls to the section, drag the controls that you want from the Controls task pane into the section on your form template.
Note: You should not move a control that is already on the form template into the section, unless the control's field is already part of the section's group in the data source. Otherwise, the binding for the control may break.
-
To add a label to the control, type text above it.
Insert a section on a form template that is based on an existing data source
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. In this scenario, you can add a section either by dragging a repeating group from the Data Source task pane onto the form template or by inserting the section by using the Controls task pane, as described in the following procedure:
-
On the form template, place the cursor where you want to insert the control.
-
If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.
-
Under Insert controls, click Section.
-
In the Section Binding dialog box, select the group in which you want to store section data, and then click OK.
-
Add controls to the section, and then bind them to the appropriate fields in the data source.
Hide a section based on values in the form
Conditional formatting isn't just for applying formatting changes to controls. One of the best ways to use conditional formatting is to show or hide a control that is based on the value that is entered in another control. A typical way to do this is to design your form with a check box above a section, so that selecting the check box shows or hides the section. This technique makes it easy for you to show the right information at the right time.
This procedure assumes that you already added a section to your form template.
-
On the form template, click the section that you want to hide.
-
On the Format menu, click Conditional Formatting.
-
In the Conditional Formatting dialog box, click Add.
-
Under If this condition is true, set the condition that you want. For example, to hide the section that you selected in step 1 when a particular check box is selected, select the field to which the check box is bound in the first box, and then specify the value that will determine whether to hide the section.
Tip: For check boxes, by default, TRUE means "selected" or "checked," whereas FALSE means the same thing as "cleared" or "unchecked."
-
Under Then apply this formatting, click Hide this control.
-
To save the condition and return to the form template, click OK twice.
-
To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.
Layout tips
Before you insert controls onto a section on a form template, think about how you want to arrange those controls. You can add text boxes and other controls by dragging them into the section wherever you want. Or if you want more control over the layout, you can add a layout table inside the section and then insert labels and controls inside the individual cells so that they align nicely. In the following example, the form designer used a two-row, three-column layout table to arrange controls inside a section.
In addition to using layout tables, you can do one or more of the following:
-
To change the size of several sections at once, select the sections whose size you want to change, press ALT+ENTER, click the Size tab, and then make the necessary adjustments.
-
To change the border or color of a section, select it on the form template, on the Format menu, click Borders and Shading, click the Borders tab, and then make the necessary adjustments.
-
To see how the controls in your section will look with actual text in them, click Sample Data on the View menu. This helps you get a sense of what a form based on your form template will look like when a user fills it out.
-
On occasion, the text inside the controls in a section and the labels to the left of those controls may appear to be slightly out of alignment. To quickly realign them, double-click the control, click Align on the Size tab, and then click Apply. If the label and control are in different cells in a layout table, right-click the cell that contains the label, click Table Properties on the shortcut menu, and then click Center under Vertical alignment on the Cell tab.
No comments:
Post a Comment