View.GetSelectedNodes method

Office 2013 and later

Gets a reference to an XMLNodesCollection collection that is populated with XML Document Object Model (DOM) nodes based on the current selection of items in a view.

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

XMLNodesCollection GetSelectedNodes()

Return value

Type: Microsoft.Office.Interop.InfoPath.SemiTrust.XMLNodesCollection
A reference to the XMLNodesCollection collection.

If no items are selected in a view, or if only text is selected, then the GetSelectedNodes method returns an empty collection.


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

Important noteImportant

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.

In the following example, the GetSelectedNodes method of the ViewObject object is used to set a reference to a collection of XML DOM nodes based on what is currently selected in the view. Then the code determines whether nodes were returned and, if they were, displays information about the first node found in the XMLNodesCollection collection in a message box.

XMLNodesCollection selectedNodes = thisXDocument.View.GetSelectedNodes();

if (selectedNodes.Count > 0)
 thisXDocument.UI.Alert(selectedNodes[0].nodeName + "\n\n" + selectedNodes[0].text);