Selecting Multiple List Box Items

Applies to TestComplete 12.60, last modified on September 17, 2018

While testing list box 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 working with list box controls, you often need to select its items. If a list box control supports multiple selection, you can select several items using specific properties and methods provided by the Win32ListBox object, which corresponds to the standard Windows list box controls. You can select the desired items in the following ways:

  • You can use the MultiSelect action, which selects several items, specified by their captions. The following code snippet demonstrates how to select a set of items:

    JavaScript, JScript

    ...
    Str = "ItemCaption1|ItemCaption2|ItemCaption3|ItemCaption5";
    ListBox.MultiSelect(Str);
    ...

    Python

    ...
    Str = "ItemCaption1|ItemCaption2|ItemCaption3|ItemCaption5"
    ListBox.MultiSelect(Str)
    ...

    VBScript

    ...
    Str = "ItemCaption1|ItemCaption2|ItemCaption3|ItemCaption5"
    ListBox.MultiSelect(Str)
    ...

    DelphiScript

    ...
    Str := 'ItemCaption1|ItemCaption2|ItemCaption3|ItemCaption5';
    ListBox.MultiSelect(Str);
    ...

    C++Script, C#Script

    ...
    Str = "ItemCaption1|ItemCaption2|ItemCaption3|ItemCaption5";
    ListBox["MultiSelect"](Str);
    ...

  • You can select several items using Ctrl- or Shift-clicks. When you perform Ctrl-click on an item, the item is added or removed from the selection. Performing Shift-clicks allow you to select a set of items between the previously selected item and the clicked item. You can simulate holding of the Ctrl or Shift key by specifying the Shift parameter of the Click action. The following code snippet selects a set of items, which includes first, second, third and fifth items:

    JavaScript, JScript

    ...
    ListBox.ClickItem("ItemCaption1");
    ListBox.ClickItem("ItemCaption3", skShift);
    ListBox.ClickItem("ItemCaption5", skCtrl);
    ...

    Python

    ...
    ListBox.ClickItem("ItemCaption1")
    ListBox.ClickItem("ItemCaption3", skShift)
    ListBox.ClickItem("ItemCaption5", skCtrl)
    ...

    VBScript

    ...
    ListBox.ClickItem "ItemCaption1"
    ListBox.ClickItem "ItemCaption3", skShift
    ListBox.ClickItem "ItemCaption5", skCtrl
    ...

    DelphiScript

    ...
    ListBox.ClickItem('ItemCaption1');
    ListBox.ClickItem('ItemCaption3', skShift);
    ListBox.ClickItem('ItemCaption5', skCtrl);
    ...

    C++Script, C#Script

    ...
    ListBox["ClickItem"]("ItemCaption1");
    ListBox["ClickItem"]("ItemCaption3", skShift);
    ListBox["ClickItem"]("ItemCaption5", skCtrl);
    ...

See Also

Working With List Box Controls
MultiSelect Action (ListBox Controls)
Click Action
Selecting a Single List Box Item

Highlight search results