InfoPath 2007 and the Multi Select List Box

The Multiple Selection List box is a new control for InfoPath 2007. As the name implies this control enables form users to select more than one option when completing a form.

In this example we will take a look at how this control can be used.

Create a new InfoPath form and then add the multiple selection list box with two buttons. In this example we will use the two buttons to retrieve the selected values within the control.

Accessing the XML data within an InfoPath 2007 form using the managed code object model typically involves creating an instance of the XPathNavigator class of the System.XML.XPath namespace. The most commonly used method of the System.Xml.XPath namespace is the XPathNavigator class is the CreateNavigator method of the DataSource class. The CreateNavigator method creates an XPathNavigator object that is positioned at the root of the data source represented by the DataSource object. For example you can use the CreateNavigator method to access the main data source, which is the underlying XML document of the form.

To retrieve the entire XML document we can use the following code:

 

When run this displays the following:

To retrieve the selected values we can use the following code

When run this shows the following