Sorting Content in Desktop Windows Applications

Applies to TestComplete 15.47, last modified on January 20, 2023

While testing header 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.

A header item can display an up or down arrow that indicates that the content of the related control is sorted by this column. When testing a header control, you may need to determine whether an item has an arrow or set the up or down arrow for the needed column. To let you work with header controls, TestComplete provides the Win32Header object. This object is automatically associated with all header controls whose class names are listed in the Object Mapping list of the current project’s options.

You can check whether an item has an arrow or set an arrow via the wSort property. This property returns 0 if the specified item does not have any arrows, 1 if the specified item shows the up arrow, and 2 if the specified item shows the down arrow.

Another way to set an arrow is to click on the needed header item. There are two types of actions that allow you to simulate a click:

To determine whether the needed item has an arrow, use the IsSortDown and IsSortUp properties of the Win32HeaderItemFormat object. For detailed information on how to work with Win32HeaderItemFormat, see Determining Header Items' Format Settings in Desktop Windows Applications.

The following code snippet obtains information about the first header item. If the item already has an arrow, it posts the arrow type to the test log. Otherwise, it sets the up arrow for this item:

JavaScript, JScript

function Main()
{
  var p, w, Header, ItemFormat;

  // Obtain the Explorer process, window and the header control
  WshShell.Run("explorer.exe c:", SW_NORMAL);
  p = Sys.Process("Explorer")
  w = p.Window("CabinetWClass", "SYSTEM (C:)", 1).Window("SHELLDLL_DefView", "", 1).Window("DUIViewWndClassName", "", 1).Window("DirectUIHWND", "", 1).Window("CtrlNotifySink", "", 1).Window("SysListView32", "FolderView", 1);
  w.Keys("[Apps]");
  w.PopupMenu.Click("View|Details");
  Header = w.Window("SysHeader32", "", 1);
  
  // Check whether the specified header item has an arrow
  ItemFormat = Header.wFormat(0)
  if (ItemFormat.IsSortDown != true)
  {
    if (ItemFormat.IsSortUp != true)
      Header.ClickItem(0)
    else Log.Message("The item has the up arrow")
  }
  else Log.Message("The item has the down arrow")
}

Python

def Main():
  
  # Obtain the Explorer process, window and the header control
  WshShell.Run("explorer.exe c:", SW_NORMAL) 
  p = Sys.Process("Explorer")
  w = p.Window("CabinetWClass", "SYSTEM (C:)", 1).Window("SHELLDLL_DefView", "", 1).Window("DUIViewWndClassName", "", 1).Window("DirectUIHWND", "", 1).Window("CtrlNotifySink", "", 1).Window("SysListView32", "FolderView", 1)
  w.Keys("[Apps]")
  w.PopupMenu.Click("View|Details")
  Header = w.Window("SysHeader32", "", 1)
  
  # Check whether the specified header item has an arrow
  ItemFormat = Header.wFormat[0] 
  if not ItemFormat.IsSortDown:
    if not ItemFormat.IsSortUp:
      Header.ClickItem(0)
    else:
      Log.Message("The item has the up arrow")
  else:
    Log.Message("The item has the down arrow")

VBScript

Sub Main
  Dim p, w, Header, ItemFormat

  ' Obtain the Explorer process, window and the header control
  Call WshShell.Run("explorer.exe c:", SW_NORMAL)
  Set p = Sys.Process("Explorer")
  Set w = p.Window("CabinetWClass", "SYSTEM (C:)", 1).Window("SHELLDLL_DefView", "", 1).Window("DUIViewWndClassName", "", 1).Window("DirectUIHWND", "", 1).Window("CtrlNotifySink", "", 1).Window("SysListView32", "FolderView", 1)
  w.Keys "[Apps]"
  w.PopupMenu.Click("View|Details")
  Set Header = w. Window("SysHeader32", "", 1)

  ' Check whether the specified header item has an arrow
  Set ItemFormat = Header.wFormat(0)
  If ItemFormat.IsSortDown <> True Then
    If ItemFormat.IsSortUp <> True Then 
      Header.ClickItem(0)
    Else Log.Message("The item has the up arrow")
    End If 
  Else Log.Message("The item has the down arrow")
  End If
End Sub 

DelphiScript

procedure Main();
var 
  p, w, i, Header, ItemFormat: OleVariant;
begin
  // Obtain the Explorer process, window and the header control
  WshShell.Run('explorer.exe c:', SW_NORMAL);
  p := Sys.Process('Explorer');
  w := p.Window('CabinetWClass', 'SYSTEM (C:)', 1).Window('SHELLDLL_DefView', '', 1).Window('DUIViewWndClassName', '', 1).Window('DirectUIHWND', '', 1).Window('CtrlNotifySink', '', 1).Window('SysListView32', 'FolderView', 1);
  w.Keys('[Apps]');
  w.PopupMenu.Click('View|Details');
  Header := w.Window('SysHeader32', '', 1);
  
  // Check whether the specified header item has an arrow
  ItemFormat := Header.wFormat(0);
  if (ItemFormat.IsSortDown <> true) then
    begin
    if (ItemFormat.IsSortUp <> true) then 
      Header.ClickItem(0)
    else Log.Message('The item has the up arrow')
    end
  else Log.Message('The item has the down arrow');
end;

C++Script, C#Script

function Main()
{
  var p, w, Header, ItemFormat;

  // Obtain the Explorer process, window and the header control
  WshShell.Run("explorer.exe c:", SW_NORMAL);
  p = Sys["Process"]("Explorer");
  w = p["Window"]("CabinetWClass", "SYSTEM (C:)", 1)["Window"]("SHELLDLL_DefView", "", 1)["Window"]("DUIViewWndClassName", "", 1)["Window"]("DirectUIHWND", "", 1)["Window"]("CtrlNotifySink", "", 1)["Window"]("SysListView32", "FolderView", 1);
  w["Keys"]("[Apps]");
  w["PopupMenu"]["Click"]("View|Details");
  Header = w["Window"]("SysHeader32", "", 1);
  
  // Check whether the specified header item has an arrow
  ItemFormat = Header["wFormat"](0);
  if (ItemFormat["IsSortDown"] != true)
  {
    if (ItemFormat["IsSortUp"] != true)
      Header["ClickItem"](0)
    else Log["Message"]("The item has the up arrow")
  }
  else Log["Message"]("The item has the down arrow")
}

See Also

Working With Header Controls in Desktop Windows Applications
ClickItem Action (Header Controls)
wSort Property (Header Controls)
IsSortUp Property (HeaderItemFormat Objects)
IsSortDown Property (HeaderItemFormat Objects)
Determining Header Items' Format Settings in Desktop Windows Applications

Highlight search results