View.GetSelectedNodes Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a reference to an XPathNodeIterator object for iterating over all XML nodes in the current selection of items in a view.
public:
abstract System::Xml::XPath::XPathNodeIterator ^ GetSelectedNodes();
public abstract System.Xml.XPath.XPathNodeIterator GetSelectedNodes ();
abstract member GetSelectedNodes : unit -> System.Xml.XPath.XPathNodeIterator
Public MustOverride Function GetSelectedNodes () As XPathNodeIterator
Returns
An XPathNodeIterator for iterating all over nodes in the current selection.
Exceptions
The GetSelectedNodes method was called from an event handler for the Loading event.
Examples
In the following example, the SelectNodes(XPathNavigator) 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
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 InfoPath Filler.