Working With Grids - Basic Concepts

Applies to TestComplete 14.0, last modified on January 23, 2019

TestComplete automatically detects the type of a grid control, with which you are working when recording and creating tests. If the grid is supported, you can call specific methods for it. For instance, you can use specific methods to click grid cells, retrieve and modify values in grid cells, and so on. These methods belong to specific program objects that are automatically associated with grid controls during the script run. You call these methods the same way you call other methods of an object, that is, object.spec_method. No specific notation is needed.

The code snippet below demonstrates how you can click a grid cell and change its value:

JavaScript

function Test()
{
  var p, w;
  // Obtain the grid object
  p = Sys.Process("DatawViewSample");
  w = p.WinFormsObject("Form1").WinFormsObject("dataGridView1");
  // Call a control-specific method
  w.ClickCell(0, "Customer Name");
  // Assign value to a control-specific property
  w.$set("wValue", 0, "Customer Name", "Samuel Clemens");
}

JScript

function Test()
{
  var p, w;
  // Obtain the grid object
  p = Sys.Process("DatawViewSample");
  w = p.WinFormsObject("Form1").WinFormsObject("dataGridView1");
  // Call a control-specific method
  w.ClickCell(0, "Customer Name");
  // Assign value to a control-specific property
  w.wValue(0, "Customer Name") = "Samuel Clemens";
}

Python

def Test():
  # Obtain the grid object
  p = Sys.Process("DatawViewSample")
  w = p.WinFormsObject("Form1").WinFormsObject("dataGridView1")
  # Call a control-specific method
  w.ClickCell(0, "Customer Name")
  # Assign value to a control-specific property
  w.wValue[0, "Customer Name"] = "Samuel Clemens"

VBScript

Sub Test
  Dim p, w
  ' Obtain the grid object
  Set p = Sys.Process("DatawViewSample")
  Set w = p.WinFormsObject("Form1").WinFormsObject("dataGridView1")
  ' Call a control-specific method
  Call w.ClickCell(0, "Customer Name")
  ' Assign value to a control-specific property
  w.wValue(0, "Customer Name") = "Samuel Clemens"
End Sub

DelphiScript

procedure Test;
var p, w : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('DatawViewSample');
  w := p.WinFormsObject('Form1').WinFormsObject('dataGridView1');
  // Call a control-specific method
  w.ClickCell(0, 'Customer Name');
  // Assign value to a control-specific property
  w.wValue[0, 'Customer Name'] := 'Samuel Clemens';
end;

C++Script, C#Script

function Test()
{
  var p, w;
  // Obtain the grid object
  p = Sys["Process"]("DatawViewSample");
  w = p["WinFormsObject"]("Form1")["WinFormsObject"]("dataGridView1");
  // Call a control-specific method
  w["ClickCell"](0, "Customer Name");
  // Assign value to a control-specific property
  w["wValue"](0, "Customer Name") = "Samuel Clemens";
}

Supported Grid Controls

Currently, TestComplete provides extended support for the following grid controls:

Note, in order for TestComplete to recognize grid controls that are inherited from the listed controls, you should specify the derived control’s class name in the corresponding group of the project’s Object Mapping options. For instance, to map a DataGridView descendant to the MicrosoftDataGridView scripting object, add the control’s class name (including the namespace) to the Microsoft Controls | WinForms | DataGridView group. After the control has been mapped, TestComplete extends its functionality with properties, methods and actions specific to the corresponding scripting object (in our example - MicrosoftDataGridView). For more information on this technique, see Object Mapping.

Basic Principles

The objects listed above use the same principles for simulating user actions over controls:

  • For each method that simulates a click or double-click on a grid cell, you can specify the grid column using its index or caption.

    Indexes are zero-based and correspond to the column’s position in the grid’s internal columns collection. So, the column index does not necessarily correspond to its visible position in the grid.

    When specifying a caption, you can use wildcards (* and ?) or regular expressions. The asterisk (*) corresponds to a string of any length (including an empty string), the wildcard question mark corresponds to any single character (including none). To specify more complicated parts of a caption, use regular expressions.

    The methods and properties can treat the captions as case-sensitive or case-insensitive depending on the Use case-sensitive parameters project settings (you can change it in the Properties page of your project’s editor).

  • All methods that simulate user actions (ClickCell, ClickRowIndicator, ClickColumnHeader, Keys, etc.) activate the window, where they should simulate the actions. The only exception is Sys.Keys; it sends keystrokes to the currently focused window.

  • All methods that simulate user actions automatically scroll the grid so that the desired element becomes visible. Also, if the ClickCell action is applied to the cell which is hidden under a collapsed group, the group is automatically expanded.

When recording actions with the listed grid controls, the following principles are used:

  • In all methods that simulate user actions with grid cells and column headers, columns are recorded using their captions.

  • If a grid cell uses a specific in-place editor (for example, an editor with embedded buttons), clicks on grid cells are recorded with coordinates, that is, as ClickCellXY actions. The same concerns recording clicks on column headers that include custom elements -- they are recorded as ClickColumnHeaderXY actions.

  • Clicks on rows’ expand buttons are recorded as Expand and Collapse actions.

See Also

Working With Grids
Object-Specific Tasks
Simulating User Actions
Supported Controls

Highlight search results