Show All

# Custom menus in the User Interface developer sample form

Microsoft Office InfoPath 2003 provides the ability to control where and how you want menu items to appear within the user interface, primarily by enabling or disabling them on various built-in menus used with a form. Some of the menus that you can customize include View, Insert, and Table, as well as shortcut menus that are displayed when a user clicks the shortcut menu button associated with a certain repeating table, repeating section, or optional section. Menus can be customized for repeating tables, repeating sections, optional sections, and views.

Note Many of the other standard InfoPath menus can also be customized; the User Interface developer sample form demonstrates how to customize a select few.

Several custom menus are implemented in the User Interface developer sample form. The following table lists the views, tables, and sections of the User Interface developer sample form, along with the custom menu items that were implemented for each of them.

Name | Type | Custom menu items
--- | --- | ---
CD Collection | View | CD Collection menu item on the View menu.
All Tracks | View | All Tracks menu item on the View menu.
CD | Repeating section | CD menu item on the Section submenu of the Insert menu. Insert CD above, Insert CD below, and Remove CD menu items on the shortcut menu for the CD table.
Track | Repeating table | Track menu item on the Section submenu of the Insert menu. Insert Track menu item on the shortcut menu for the CD table. Insert Tracks and Remove Tracks menu items on the Table menu. Insert Track above, Insert Track below, and Remove Track menu items on the shortcut menu for the Track table.
Label | Optional section | Label menu item on the Section submenu of the Insert menu. Insert Label menu item on the shortcut menu for the CD table. Remove Label menu item on the shortcut menu for the Label control.

Note When you customize menus in InfoPath, those customizations are applied at the view level. This means that the customizations you make are not globally applied to all views. To apply the same custom menus to more than one view, you must make the menu customizations in each view.

Customizing the View menu

The User Interface developer sample form implements two views: CD Collection view is used to create a collection of CD information including Artist, Title, Track, and Label; All Tracks view is used to list all of the tracks within the CD collection. CD Collection view is the default view that users see when they first open the form. To switch between the two views while filling out the form, users can select a view from the View menu.

To make views available to users on the View menu, you select the Show on the View menu when filling out the form check box in the View Properties dialog box in design mode. You can access the View Properties dialog box by selecting a view in the Views task pane and clicking View Properties.

Note If you have only one view in your form, the Show on the View menu when filling out the form check box is disabled. Since there is only one view in the form, users do not need to select it because it is always the default view.

When you create a view in InfoPath and enable it for the View menu, InfoPath creates an entry in the form definition (.xsf) file using a menuArea element whose name attribute value is msoViewMenu. It also creates a button element within the menuArea element for each view that will have a menu item on the View menu. The caption that appears as a menu item on the View menu is determined by the caption attribute of the button element in the .xsf file. InfoPath uses the name of the view for the caption, but you can override this by changing the value of the caption attribute in the button element.

Note If you change the caption attribute in the .xsf file, and later change some properties of the view by using the View Properties dialog box, InfoPath overwrites your changes in the .xsf file, so you must reset the value of the caption attribute.

The following is a section from the .xsf file of the User Interface developer sample form that contains the menuArea element for the View menu:

    <xsf:menuArea name="msoViewMenu">
       <xsf:button
          caption="CD Collection"
          name="SwitchToView0">
       </xsf:button>
       <xsf:button
          caption="All Tracks"
          name="SwitchToView1">
       </xsf:button>
    </xsf:menuArea>

Customizing the Insert menu

The Insert menu is typically used to insert common items such as tables, pictures, and hyperlinks while filling out a form. However, you can customize the Insert menu to allow for insertion of repeating tables, repeating sections, and optional sections. In the User Interface developer sample form, the Insert menu is customized to allow for insertion of a CD, Track, or Label.

Two types of customizations can be made on the Insert menu. One is to add a menu item directly on the Insert menu; the other is to create a menu item on the Section submenu of the Insert menu. The User Interface developer sample form creates a menu item on the Section submenu.

To customize the Insert menu in design mode, you use the Properties dialog box of the particular repeating section, repeating table, or optional section that you want to appear on the menu. The Properties dialog box can be accessed by right-clicking the section or table that you are working with, and then clicking the Properties menu item on the shortcut menu. To customize the Insert menu for repeating tables and optional sections, you can click Customize Commands on the Data tab to open the Commands dialog box. For repeating sections, the Customize Commands button is available in the Section Properties dialog box that opens when you choose to modify the default settings of a section. The Section Commands dialog box allows you to associate certain editing actions with various command locations available on the menus in an InfoPath form.

When you add custom menu items to the Insert menu, InfoPath creates an entry in the form definition (.xsf) file using a menu element, nested inside a menuArea element whose name attribute value is msoInsertMenu, with button elements nested inside the menu element. The caption attribute of the menu element determines the section name that appears on the menu, and the caption attribute of the button elements determines the names of the buttons on the submenu. In addition to the caption attribute, the button element also has a showIf attribute that determines when the menu item is enabled.

The following is a section from the .xsf file of the User Interface developer sample form that contains the menuArea element for the Insert menu:

    <xsf:menuArea name="msoInsertMenu">
       <xsf:menu caption="&amp;Section">
          <xsf:button
             action="xCollection::insert"
             xmlToEdit="CD_10"
             caption="CD"
             showIf="always">
          </xsf:button>
          <xsf:button
             action="xCollection::insert"
             xmlToEdit="Track_14"
             caption="Track"
             showIf="always">
          </xsf:button>
          <xsf:button
             action="xOptional::insert"
             xmlToEdit="Label_16"
             caption="Label">
          </xsf:button>
       </xsf:menu>
    </xsf:menuArea>

Note Using the `&amp;` predefined entity reference in the caption attribute of the menu element makes the character immediately following the entity reference the keyboard shortcut for the menu item.

Customizing the Table menu

The Table menu is typically used to insert, delete, and work with tables when filling out a form. However, you can customize the Table menu to allow for insertion or removal of repeating tables, repeating sections, and optional sections. In the User Interface developer sample form, the Table menu is customized to allow for insertion or removal of CD Tracks. While it is possible to use the Table menu to work with repeating and optional sections, the Table menu is optimized for, and generally best for, working with repeating tables.

To customize the Table menu in design mode, you click Customize Commands in the Repeating Tables Properties dialog box for the repeating table you are working with. Then you select the editing action and set its command location to Table menu in the Table Commands dialog box. When you customize the Table menu, menu items are placed directly on the Table menu. However, it is possible to create submenus on the Table menu to which you can add menu items. This is accomplished by nesting the button elements within a menu element in the form definition (.xsf) file. The caption that appears for the submenu is determined by the caption attribute of the menu element.

Note Using submenus in custom menus is a feature of the .xsf file and is not available when using the Customize Commands dialog box in design mode.

The following is a section from the .xsf file of the User Interface developer sample form that contains the menuArea element for the Table menu:

    <xsf:menuArea name="msoTableMenu">
       <xsf:menu caption="Insert Tracks">
          <xsf:button
             action="xCollection::insertBefore"
             xmlToEdit="Track_14"
             caption="Above"
             showIf="always">
          </xsf:button>
          <xsf:button
             action="xCollection::insertAfter"
             xmlToEdit="Track_14"
             caption="Below"
             showIf="always">
          </xsf:button>
       </xsf:menu>
       <xsf:menu caption="Remove Tracks">
          <xsf:button
             action="xCollection::remove"
             xmlToEdit="Track_14"
             caption="Remove Current Row"
             showIf="always">
          </xsf:button>
       </xsf:menu>
    </xsf:menuArea>

Customizing shortcut menus

The shortcut menus that are associated with repeating sections, repeating tables, and optional sections can be customized to allow users to select various editing actions. Users access them by clicking the shortcut menu button when a certain section, table, or field on a form is selected.

To customize the shortcut menu in design mode, you click Customize Commands in the Properties dialog box for the repeating table or optional section you are working with, select the editing action, and set its command location to Shortcut menu in the Commands dialog box. For repeating sections, the Customize Commands button is available in the Section Properties dialog box that opens when you choose to modify the default settings of a section.

When you customize a shortcut menu, InfoPath creates an entry in the form definition (.xsf) file using a menuArea element whose name attribute value is msoStructuralEditingContextMenu, along with nested button elements. In the User Interface developer sample form, many of the default captions used for menu items on the shortcut menu were overridden by modifying the value of the caption attribute in the button elements of the .xsf file.

The following is a section from the .xsf file of the User Interface developer sample form that contains the menuArea element for the shortcut menu:

    <xsf:menuArea name="msoStructuralEditingContextMenu">
       <xsf:button
          action="xCollection::insertBefore"
          xmlToEdit="CD_10"
          caption="Insert CD above"
          showIf="immediate">
       </xsf:button>
       <xsf:button
          action="xCollection::insertBefore"
          xmlToEdit="Track_14"
          caption="Insert Track above"
          showIf="immediate">
       </xsf:button>
       ...
    </xsf:menuArea>

©2003-2004 Microsoft Corporation. All rights reserved. Permission to copy, display and distribute this document is available at: http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp