共用方式為


View2.SelectNodes 方法

根據指定的起始 XML 文件物件模型 (DOM) 節點、結束 XML DOM 節點及檢視內容,在檢視中選取節點範圍。

**命名空間:**Microsoft.Office.Interop.InfoPath
**組件:**Microsoft.Office.Interop.InfoPath (於 microsoft.office.interop.infopath.dll 中)

語法

'宣告
<DispIdAttribute(12)> _
Sub SelectNodes ( _
    <InAttribute> pxnStartNode As IXMLDOMNode, _
    <InAttribute> <OptionalAttribute> varEndNode As Object, _
    <InAttribute> <OptionalAttribute> varViewContext As Object _
)
'用途
Dim instance As View2
Dim pxnStartNode As IXMLDOMNode
Dim varEndNode As Object
Dim varViewContext As Object

instance.SelectNodes(pxnStartNode, varEndNode, varViewContext)
[DispIdAttribute(12)] 
void SelectNodes (
    [InAttribute] IXMLDOMNode pxnStartNode,
    [OptionalAttribute] [InAttribute] Object varEndNode,
    [OptionalAttribute] [InAttribute] Object varViewContext
)

參數

  • pxnStartNode
    開始範圍的 XML DOM 節點。
  • varEndNode
    結束範圍的 XML DOM 節點。如果未指定,只會使用起始 XML DOM 節點。
  • varViewContext
    內容中使用的控制項識別碼,是具有指定 xd:CtrlId 檢視內容的元素。

備註

如果已指定檢視內容,要選取的所有 XML DOM 節點都必須在該內容中。

如果 SelectNodes 方法的任一引數為 null,或未顯示於檢視中,則 SelectNodes 方法會傳回錯誤。此外,如果在指定的檢視內容中,有多組檢視元素對應到同一指定的 XML DOM 節點,則 SelectNodes 方法也會傳回錯誤。

注意

SelectNodes 方法會要求節點在檢視中必須能以結構化方式選取。

範例

在下列範例中,ViewObject 物件的 SelectNodes 方法是用於在檢視的單一項目上設定選取範圍,對應於指定的 XML DOM 節點。接著程式碼使用 View 物件的 GetSelectedNodes 方法,在訊息方塊中顯示 XML DOM 節點的相關資訊,判斷選取是否順利完成。此範例需要名為 group1 的重複表格。出現的第一個項目會先行選取:

XMLNodesCollection selectedNodes;
IXMLDOMNode group1;
group1 = thisXDocument.DOM.selectSingleNode(@"//my:group1");
thisXDocument.View.SelectNodes(group1, Type.Missing, Type.Missing);
selectedNodes = thisXDocument.View.GetSelectedNodes();
if (selectedNodes.Count > 0)
 {
  thisXDocument.UI.Alert(selectedNodes[0].nodeName + "\n\n" + selectedNodes[0].text);
 }

請參閱

參考

View2 介面
View2 成員
Microsoft.Office.Interop.InfoPath 命名空間