View.GetSelectedNodes Method (Microsoft.Office.InfoPath)
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)
Syntax
'Declaration
Public MustOverride Function GetSelectedNodes As XPathNodeIterator
'Usage
Dim instance As View
Dim returnValue As XPathNodeIterator
returnValue = instance.GetSelectedNodes
public abstract XPathNodeIterator GetSelectedNodes ()
Return Value
An XPathNodeIterator for iterating all over nodes in the current selection.
Exceptions
Exception type | Condition |
---|---|
The GetSelectedNodes method was called from an event handler for the Loading event. |
Remarks
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.
Note
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 Office InfoPath 2007.
Example
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 =
MainDataSource.CreateNavigator().SelectSingleNode(
"/my:myFields/my:group1/my:group2[1]", NamespaceManager);
// Select nodes in specified XPathNavigator.
CurrentView.SelectNodes(repeatingTableRow1);
// Get selected nodes.
XPathNodeIterator selectedNodes =
CurrentView.GetSelectedNodes();
// Display the count of selected nodes.
MessageBox.Show(selectedNodes.Count.ToString());
// Loop through collection and display information.
foreach (XPathNavigator selectedNode in selectedNodes)
{
MessageBox.Show(selectedNode.Name);
MessageBox.Show(selectedNode.InnerXml);
MessageBox.Show(selectedNode.Value);
}
' Create XPathNavigator and specify XPath for nodes.
Dim repeatingTableRow1 As XPathNavigator = _
CreateNavigator().SelectSingleNode( _
"/my:myFields/my:group1/my:group2[1]", NamespaceManager)
' Select nodes in specified XPathNavigator.
CurrentView.SelectNodes(repeatingTableRow1)
' Get selected nodes.
Dim selectedNodes As XPathNodeIterator = _
CurrentView.GetSelectedNodes()
' Display the count of selected nodes.
MessageBox.Show(selectedNodes.Count.ToString())
' Loop through collection and display information.
Dim selectedNode As XPathNavigator
For Each selectedNode In selectedNodes
MessageBox.Show(selectedNode.Name)
MessageBox.Show(selectedNode.InnerXml)
MessageBox.Show(selectedNode.Value)
Next