SelectItem Method (Specific to Win32TreeView Controls)

Applies to TestComplete 15.42, last modified on September 08, 2022

Description

The SelectItem action sets the tree view selection to the item specified by the Item parameter. Note that the item is selected, but the mouse pointer is not moved to it, as it would be with ClickItem or DblClickItem.

Declaration

TestObj.SelectItem(Item)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
Item [in]    Required    Variant    
Result None

Applies To

The method is applied to the following object:

View Mode

To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Parameters

The method has the following parameter:

Item

Specifies the path to the desired item. The path should be relative to the current item or to the tree root, respectively. To indicate that the path starts from the tree root, place the pipeline character ( | ) at the beginning of the path.

Each item in the path can be specified by its caption or index; individual captions and indexes must be separated with pipeline characters ( | ). Indexes must be enclosed in brackets - [ and ].

To indicate variable parts of the item caption, you can use the asterisk (*) and question mark (?) wildcards. The asterisk corresponds to a string of any length, the question mark corresponds to any single character. The caption can be case-sensitive or case-insensitive depending on the value of the Use case-sensitive parameters project setting.

Note: If the item caption includes a bracket or a pipeline character, address the item by its index or with the question mark wildcard.

Result Value

None.

Remarks

If the specified item is not found, SelectItem fails and posts an error message to the test log.

Example

The following example demonstrates how you can use the SelectItem method in scripts:

JavaScript, JScript

function TreeViewSample()
{
 var p, TreeView;
 // Obtain the application process and the TreeView control
 p = Sys.Process("MyTestedApp");
 TreeView = p.Window("MyWndClass", "*").Window("SysTreeView32");
 
  // Click some items
 TreeView.SelectItem(0);
 TreeView.SelectItem("|Root1|Child5");
 
 TreeView.wItems.Item("Root2").Items.Item("Child4").Select();
 TreeView.wItems.Item("Root1").Select();
}

Python

def TreeViewSample():

  # Obtain the application process and the TreeView control
  p = Sys.Process("MyTestedApp")
  TreeView = p.Window("MyWndClass", "*").Window("SysTreeView32")
  
  # Click some items
  TreeView.SelectItem(0)
  TreeView.SelectItem("|Root1|Child5")

  TreeView.wItems.Item["Root2"].Items.Item["Child4"].Select()
  TreeView.wItems.Item["Root1"].Select()

VBScript

Sub TreeViewSample
  Dim p, TreeView

  ' Obtain the application process and the TreeView control
  Set p = Sys.Process("MyTestedApp")
  Set TreeView = p.Window("MyWndClass", "*").Window("SysTreeView32")

  ' Click some items
  TreeView.SelectItem(0)
  TreeView.SelectItem("|Root1|Child5")

  TreeView.wItems.Item("Root2").Items.Item("Child4").Select()
  TreeView.wItems.Item("Root1").Select()

End Sub

DelphiScript

procedure TreeViewSample;
var p, TreeView : OleVariant;
begin
  // Obtain the application process and the TreeView control
  p := Sys.Process('MyTestedApp');
  TreeView := p.Window('MyWndClass', '*').Window('SysTreeView32');
  
  // Click some items
  TreeView.SelectItem(0);
  TreeView.SelectItem('|Root1|Child5');

  TreeView.wItems.Item('Root2').Items.Item('Child4').Select();
  TreeView.wItems.Item('Root1').Select();
end;

C++Script, C#Script

function TreeViewSample()
{
  var p, TreeView;

  // Obtain the application process and the TreeView control
  p = Sys["Process"]("MyTestedApp");
  TreeView = p["Window"]("MyWndClass", "*")["Window"]("SysTreeView32");
  
  // Click some items
  TreeView["SelectItem"](0);
  TreeView["SelectItem"]("|Root1|Child5");
  
  TreeView["wItems"]["Item"]("Root2")["Items"]["Item"]("Child4")["Select"]();
  TreeView["wItems"]["Item"]("Root1")["Select"]();
}

See Also

ClickItem Action (TreeView Controls)
DblClickItem Action (TreeView Controls)
wSelection Property (Specific to Win32TreeView Controls)
Select Action (TreeViewItem Objects)

Highlight search results