View.SelectNodes Method

InfoPath Developer Reference

Selects a range of nodes in a view based on the specified starting XML Document Object Model (DOM) node, the ending XML DOM node, and the view context.

Version Information
 Version Added:  InfoPath 2003

Syntax

expression.SelectNodes(pxnStartNode, varEndNode, varViewContext)

expression   An expression that returns a View object.

Parameters

Name Required/Optional Data Type Description
pxnStartNode Required [IXMLDOMNODE] The XML DOM node that begins the range.
varEndNode Optional Variant The XML DOM node that ends the range. If not specified, only the starting XML DOM node will be used.
varViewContext Optional Variant The ID of the control that is used for the context, which is an element with the specified view context of "xd:CtrlId".

Return Value
Nothing

Remarks

If a view context is specified, all of the XML DOM nodes that are to be selected must be within that context.

If any of the arguments to the SelectNodes method are null or are not exposed in the view, the SelectNodes method will return an error. In addition, if there are more than one set of view elements which map to the same specified XML DOM nodes, within the specified view context, then the SelectNodes method will also return an error.

If you need to select a single editable field bound to a control such as a Text Box, use the SelectText method instead.

Security Level 2: 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.

Example

In the following example, the SelectNodes method of the View object is used to set selection on a single item in the view, corresponding to the specified XML DOM node. Using the GetSelectedNodes method of the View object, determines whether the selection has been successful by displaying information about the XML DOM node in a message box. This example requires a Repeating Table control bound to a repeating group named "employee". The text in the first row of the table is selected and displayed.

JScript
  function SelectEmployee()
{
   var objXMLNodes;
   var objXMLNode;
   objXMLNode = XDocument.DOM.selectSingleNode("//my:employees/my:employee");
   XDocument.View.SelectNodes(objXMLNode);
   objXMLNodes = XDocument.View.GetSelectedNodes();
   if (objXMLNodes.Count > 0)
   {
      XDocument.UI.Alert(objXMLNodes(0).nodeName + "\n\n" + objXMLNodes(0).text);
   }
}

See Also