Custom toolbars in the User Interface developer sample form

Microsoft Office InfoPath

Show All Show All

Custom toolbars in the User Interface developer sample form

The User Interface developer sample form implements a single custom toolbar, the CD Collection Toolbar, that allows users to add or remove a CD, Track, or Label. By default, Microsoft Office InfoPath 2003 has one built-in custom toolbar, the Form toolbar, that can be used to create custom menu items that users can click to perform various actions on a form.

To customize the Form toolbar in design mode, you use the Properties dialog box for the particular repeating section, repeating table, or optional section that you are working with. The Properties dialog box is accessed by right-clicking the section or table and clicking the Properties menu item on the shortcut menu. In the Properties dialog box for repeating tables and optional sections, you click Customize Commands to open the Commands dialog box. For repeating sections, the Customize Command button is available in the Section Properties dialog box that opens when you choose to modify the default settings of a section. The Commands dialog box allows you to associate certain editing actions with various command locations available on the menus and toolbars in an InfoPath form. To create a custom toolbar, you select the Form Toolbar location.

Note  In the User Interface developer sample form, the command location is the CD Collection Toolbar, since the default name of the Form toolbar was modified. Modifications to the default name of a toolbar can be made manually in the form definition (.xsf) file by changing the value of the caption attribute of the toolbar element.

When you customize a toolbar, InfoPath creates entries in the .xsf file using button elements within the toolbar element. The caption that appears as the name of the toolbar is determined by the caption attribute of the toolbar element, and the caption that appears as the name of a button on the toolbar is determined by the caption attribute of a button element.

As you associate editing actions with the custom toolbar using the Commands dialog box, menu items are placed directly on the toolbar. However, it is possible to create menus on the toolbar and then add menu items to those menus. This is accomplished by nesting the button elements of the toolbar within a menu element in the .xsf file.

The following is a section from the .xsf file of the User Interface developer sample form that contains the toolbar element. Note the use of the menu element to create a menu on the toolbar.

<xsf:toolbar 
   caption="CD Collection Toolbar" 
   name="CD Collection Toolbar">
   <xsf:button 
      action="xCollection::insert" 
      xmlToEdit="CD_10" 
      caption="New CD" 
      showIf="always">
   </xsf:button>
   <xsf:button 
      action="xCollection::insert" 
      xmlToEdit="Track_14" 
      caption="New Track" 
      showIf="always">
   </xsf:button>
   <xsf:button 
      action="xOptional::insert" 
      xmlToEdit="Label_16" 
      caption="New Label" 
      showIf="always">
   </xsf:button>
   <xsf:menu 
      caption="Remove">
      <xsf:button 
         action="xCollection::remove" 
         xmlToEdit="CD_10" 
         caption="CD" 
         showIf="always">
      </xsf:button>
      <xsf:button 
         action="xCollection::remove" 
         xmlToEdit="Track_14" 
         caption="Track" 
         showIf="always"></xsf:button>
      <xsf:button 
         action="xOptional::remove" 
         xmlToEdit="Label_16" 
         caption="Label" 
         showIf="always">
      </xsf:button>
   </xsf:menu>
</xsf:toolbar>

Notes

  • Adding menus to a toolbar is a feature of the .xsf file and is not available when using the Commands dialog box in design mode.
  • While InfoPath implements a single custom toolbar, you can add multiple toolbars to a form by creating additional toolbar elements within the .xsf file. Once you have created the additional toolbars by manually editing the .xsf file, those toolbars are available in the Commands dialog box, and you can then associate editing actions with them.