View.GetSelectedNodes method

Office 2013 and later

Gets a reference to an XPathNodeIterator object for iterating over all XML nodes in the current selection of items in a view.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

public abstract XPathNodeIterator GetSelectedNodes()

Return value

Type: System.Xml.XPath.XPathNodeIterator
An XPathNodeIterator for iterating all over nodes in the current selection.


The GetSelectedNodes method was called from an event handler for the Loading event.

If no items are selected in a view, or if only text is selected, then the XPathNodeIterator object returned by the GetSelectedNodes method has nothing to iterate over.


The GetSelectedNodes method will not return nodes based on the current selection if used in the event handler for the Clicked event of a button in the view, because the focus is lost from the control that is intended to be in context. To avoid this behavior, use GetSelectedNodes from a custom task pane, menu or toolbar.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed only from code running in forms opened in Microsoft InfoPath Filler.

In the following example, the SelectNodes method is used to select the nodes in the first row of a Repeating Table control bound to group2. The GetSelectedNodes method is then used to return a collection of nodes based on the current selection. Finally, the code loops through the collection of nodes displays the name, inner XML, and value of each node.

// Create XPathNavigator and specify XPath for nodes.
XPathNavigator repeatingTableRow1 = 
   "/my:myFields/my:group1/my:group2[1]", NamespaceManager);

// Select nodes in specified XPathNavigator.

// Get selected nodes.
XPathNodeIterator selectedNodes = 

// Display the count of selected nodes.

// Loop through collection and display information.
foreach (XPathNavigator selectedNode in selectedNodes)