Getting the Current Tree View Item in Desktop Windows Applications

Applies to TestComplete 15.45, last modified on December 01, 2022

While testing tree view controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

When testing an application that uses tree view controls, you may need to know which tree view item is currently focused. If your tested application uses standard Win32 TreeView controls, you can determine the current tree view item using the Win32TreeView.wSelection property. This property returns the full “path” to the current item, in the form “|RootItem|SubItem|SubItem|Item”. As you can see, the “path” includes the item’s text and the text of all of its parent nodes separated by pipeline characters (“|”). The path also starts with the pipeline character, which indicates that the path is absolute rather than relative to a specific node. For more information on using item “paths”, see Addressing Tree View Items in Desktop Windows Applications.

The code snippet below demonstrates the wSelection property usage. It determines the currently selected items in Windows Explorer’s Folders tree. In order for the script to execute successfully, Explorer must be running and the Folders tree must be displayed. You can turn it on by checking the View | Explorer Bar | Folders menu item or the Folders button on the toolbar.

JavaScript, JScript

function Main ()
{
  var p, w, folders;

  // Obtain the Explorer process, window and the Folders tree
  p = Sys.Process("Explorer");
  w = p.Window("*WClass", "*");
  folders = w.Window("BaseBar").Window("ReBarWindow32").Window("SysTreeView32");

  Log.Message("Current TreeView item: " + folders.wSelection);
}

Python

def Main():
  
  # Obtain the Explorer process, window and the Folders tree
  p = Sys.Process("Explorer")
  w = p.Window("*WClass", "*")
  folders = w.Window("BaseBar").Window("ReBarWindow32").Window("SysTreeView32")

  Log.Message("Current TreeView item: " + folders.wSelection)

VBScript

Sub Main
  Dim p, w, folders

  ' Obtain the Explorer process, window and the Folders tree
  Set p = Sys.Process("Explorer")
  Set w = p.Window("*WClass", "*")
  Set folders = w.Window("BaseBar").Window("ReBarWindow32").Window("SysTreeView32")

  Log.Message("Current TreeView item: " & folders.wSelection)
End Sub

DelphiScript

procedure Main;
var p, w, folders : OleVariant;
begin
  // Obtain the Explorer process, window and the Folders tree
  p := Sys.Process('Explorer');
  w := p.Window('*WClass', '*');
  folders := w.Window('BaseBar').Window('ReBarWindow32').Window('SysTreeView32');

  Log.Message('Current TreeView item: ' + folders.wSelection);
end;

C++Script, C#Script

function Main ()
{
  var p, w, folders;

  // Obtain the Explorer process, window and the Folders tree
  p = Sys["Process"]("Explorer");
  w = p["Window"]("*WClass", "*");
  folders = w["Window"]("BaseBar")["Window"]("ReBarWindow32")["Window"]("SysTreeView32");

  Log["Message"]("Current TreeView item: " + folders["wSelection"]);
}

See Also

Working With Tree View Controls in Desktop Windows Applications
wSelection Property (Specific to Win32TreeView Controls)
Getting Selected Tree View Items in Desktop Windows Applications

Highlight search results