View.GetContextNodes Method

Gets a reference to an XPathNodeIterator for iterating over the returned XML nodes in the current selection.

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

Syntax

'Declaration
Public MustOverride Function GetContextNodes As XPathNodeIterator
'Usage
Dim instance As View
Dim returnValue As XPathNodeIterator

returnValue = instance.GetContextNodes()
public abstract XPathNodeIterator GetContextNodes()

Return Value

Type: System.Xml.XPath.XPathNodeIterator
An XPathNodeIterator that is populated with the nodes in the current selection.

Exceptions

Exception Condition
InvalidOperationException

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

Remarks

The XML nodes returned by the GetContextNodes method consists of a sequence of nodes that are mapped from the view, corresponding to the selected XSL Transformation (XSLT) nodes.

If the selected nodes are bound to more than one control in the view, you must use the GetContextNodes method instead which allows you to specify the ViewContext identifier of the control that is bound to the nodes you want to iterate over.

Note

The GetContextNodes 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 GetContextNodes 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.

Examples

In the following example, the GetContextNodes method is used to return a collection of context nodes based on the current selection to populate an XPathNodeIterator object variable.The code then loops through the collection of context nodes and displays the name, inner XML, and value of each node.

// Get context nodes in current selection.
XPathNodeIterator contextNodes = 
   CurrentView.GetContextNodes();

// Loop through collection and display information.
foreach (XPathNavigator contextNode in contextNodes)
{
   MessageBox.Show(contextNode.Name);
   MessageBox.Show(contextNode.InnerXml);
   MessageBox.Show(contextNode.Value);
}
' Get context nodes in current selection.
Dim contextNodes As XPathNodeIterator = _
   CurrentView.GetContextNodes(repeatingTableRow1)

' Loop through collection and display information.
Dim contextNode As XPathNavigator
For Each contextNode In contextNodes
   MessageBox.Show(contextNode.Name)
   MessageBox.Show(contextNode.InnerXml)
   MessageBox.Show(contextNode.Value)
Next

See Also

Reference

View Class

View Members

GetContextNodes Overload

Microsoft.Office.InfoPath Namespace