Selecting Cells in Syncfusion GridGroupingControl

Applies to TestComplete 15.63, last modified on April 10, 2024

One of the actions that you will perform the most over a grid is selecting cells. This topic describes various approaches that can be used to select a particular cell in Syncfusion GridGroupingControl. Note that before selecting a cell you should identify the row and column in which the desired cell resides. For example, you can search for the row by the value or text in a particular column.

To perform these actions, TestComplete should have access to internal objects, properties and methods of the GridGroupingControl object. For this purpose, the .NET Application Support and Syncfusion Systems Control Support plugins must be installed and enabled. The latter lets you work with the GridGroupingControl controls using methods and properties of the SyncfusionEssGrid object. Without this plugin, you will not be able to work with controls using their internal methods and properties.

When testing Syncfusion GridGroupingControl controls, use specific methods and properties of the corresponding SyncfusionEssGrid object. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with an object’s properties and methods from your scripts. However, when testing a GridGroupingControl 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.

Simulating Clicks on Cells

To simulate clicks on GridGroupingControl cells, you can use the ClickCell, ClickCellR, DblClickCell and similar actions of the SyncfusionEssentialGrid or SyncfusionEssentialGridView object. All of these actions have parameters that specify the row and column that contain the desired cell. They also have an additional parameter that specifies the key or a combination of keys (Ctrl, Alt, Shift) that are pressed during the simulation of a click.

Below is an example that demonstrates how you can simulate clicks on grid cells:

Example
Note: This example works with the EmployeeTerritoryOrder sample application that is shipped with Syncfusion Essential Studio and resides in the following folder:

<Syncfusion>\Windows\Grid.Grouping.Windows\Samples\2.0\Relations And Hierarchy\Employee Territory Order Demo\

JavaScript, JScript

function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys.Process("EmployeeTerritoryOrder");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1");

  // Click cell in a root table
  Grid.ClickCell (0, "LastName");
  // Enter the new value
  Grid.Keys ("[Home]![End][Del]" + "Smith" + "[Enter]");

  // Click cell in a nested table
  Grid.wChildView(0, 1).wChildView(0, 0).ClickCell(0, "Quantity");
  // Enter the new value
  Grid.Keys ("[Home]![End][Del]" + "75" + "[Enter]");
}

Python

def Main ():
  # Obtain the grid object
  p = Sys.Process("EmployeeTerritoryOrder")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")

  # Click cell in a root table
  Grid.ClickCell (0, "LastName")
  # Enter the new value
  Grid.Keys ("[Home]![End][Del]" + "Smith" + "[Enter]")

  # Click cell in a nested table
  Grid.wChildView[0, 1].wChildView[0, 0].ClickCell(0, "Quantity")
  # Enter the new value
  Grid.Keys ("[Home]![End][Del]" + "75" + "[Enter]")

VBScript

Sub Main
  Dim p, Grid
  ' Obtain the grid object
  Set p = Sys.Process("EmployeeTerritoryOrder")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")

  ' Click cell in a root table
  Call Grid.ClickCell (0, "LastName")
  ' Enter the new value
  Call Grid.Keys ("[Home]![End][Del]" & "Smith" & "[Enter]")

  ' Click cell in a nested table
  Call Grid.wChildView(0, 1).wChildView(0, 0).ClickCell (0, "Quantity")
  ' Enter the new value
  Call Grid.Keys ("[Home]![End][Del]" & "75" & "[Enter]")
End Sub

DelphiScript

procedure Main;
var p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('EmployeeTerritoryOrder');
  Grid := p.WinFormsObject('Form1').WinFormsObject('gridGroupingControl1');

  // Click cell in a root table
  Grid.ClickCell (0, 'LastName');
  // Enter the new value
  Grid.Keys ('[Home]![End][Del]' + 'Smith' + '[Enter]');

  // Click cell in a nested table
  Grid.wChildView(0, 1).wChildView(0, 0).ClickCell(0, 'Quantity');
  // Enter the new value
  Grid.Keys ('[Home]![End][Del]' + '75' + '[Enter]');
end;

C++Script, C#Script

function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys["Process"]("EmployeeTerritoryOrder");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridGroupingControl1");

  // Click cell in a root table
  Grid["ClickCell"](0, "LastName");
  // Enter the new value
  Grid["Keys"]("[Home]![End][Del]" + "Smith" + "[Enter]");

  // Click cell in a nested table
  Grid["wChildView"](0, 1)["wChildView"](0, 0)["ClickCell"](0, "Quantity");
  // Enter the new value
  Grid["Keys"]("[Home]![End][Del]" + "75" + "[Enter]");
}

Using GridGroupingControl Internal Methods

It is possible to select a particular GridGroupingControl cell using the Record.SetCurrent_2(FieldName) method. Here, Record is the object corresponding to a data row that contains the desired cell, and FieldName is the bound dataset field name of the cell’s column (the string value returned by the column’s MappingName property).

If you use the Record.SetCurrent_2 method to select a grid cell, you do not need to perform any additional actions to make the desired cell visible since the method does it automatically. It expands the cell’s parent tables and groups so that the cell is displayed in the grid and also scrolls the cell into the grid view.

Below is an example that demonstrates how you can use the Record.SetCurrent_2 method in scripts.

Example

View description

JavaScript

function Main ()
{
  var p, Grid, Table;

  // Obtain the grid object
  p = Sys.Process("EmployeeTerritoryOrder");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1");

  // Select the cell in the root table
  SelectCell (Grid, null, 0, "FirstName");
  aqUtils.Delay (1000);
  // Select the cell in the nested table
  Table = GetNestedTable (Grid, null, 0, "Orders");
  SelectCell (Grid, Table, 10, "OrderDate");
}

function SelectCell (Grid, TableOrGroup, RowIndex, ColumnId)
{
  // Get the data row object and the column field name
  let Rec = GetRecord (Grid, TableOrGroup, RowIndex);
  let FieldName = GetColumn (Grid, TableOrGroup, ColumnId).MappingName;

  // Select the cell and check if it was selected
  if (!Rec.SetCurrent_2 (FieldName))
    Log.Error ("Cell (" + RowIndex + ", " + ColumnId + ") could not be selected.");
}

function GetNestedTable (Grid, TableOrGroup, RowIndex, TableId)
{
  // Get the root table if no table is specified
  if (strictEqual(TableOrGroup, null))
    TableOrGroup = Grid.Table.TopLevelGroup;

  // Get the nested tables collection
  var NestedTables = TableOrGroup.Records.Item_2(RowIndex).NestedTables;

  // Check if the table is specified by caption or index
  if (equal(aqObject.GetVarType (TableId), varOleStr))
    return NestedTables.Item_2(TableId).ChildTable
  else
    return NestedTables.Item(TableId).ChildTable;
}

function GetRecord (Grid, TableOrGroup, RowIndex)
{
  // Get the root table if no table is specified
  if (strictEqual(TableOrGroup, null))
    TableOrGroup = Grid.Table.TopLevelGroup;

  return TableOrGroup.Records.Item_2(RowIndex);
}

function GetColumn (Grid, Table, ColumnId)
{
  var Columns, ColDescriptor;

  // Get the table columns
  if (strictEqual(Table, null))
    Columns = Grid.TableDescriptor.Columns
  else
    Columns = Table.ParentTableDescriptor.Columns;

  if (equal(aqObject.GetVarType (ColumnId), varOleStr))
  // The column is specified by its caption
  {
    // Search for the desired column
    for (let i=0; i<Columns.Count; i++)
    {
      ColDescriptor = Columns.Item(i);
      if (equal(ColDescriptor.HeaderText.OleValue, ColumnId))
        return ColDescriptor; // Column is found
    }
  return null; // Column is not found
  }
  else
    // The column is specified by its index
    return Columns.Item(ColumnId);
}

JScript

function Main ()
{
  var p, Grid, Table;

  // Obtain the grid object
  p = Sys.Process("EmployeeTerritoryOrder");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1");

  // Select the cell in the root table
  SelectCell (Grid, null, 0, "FirstName");
  aqUtils.Delay (1000);
  // Select the cell in the nested table
  Table = GetNestedTable (Grid, null, 0, "Orders");
  SelectCell (Grid, Table, 10, "OrderDate");
}

function SelectCell (Grid, TableOrGroup, RowIndex, ColumnId)
{
  // Get the data row object and the column field name
  var Rec = GetRecord (Grid, TableOrGroup, RowIndex);
  var FieldName = GetColumn (Grid, TableOrGroup, ColumnId).MappingName;

  // Select the cell and check if it was selected
  if (!Rec.SetCurrent_2 (FieldName))
    Log.Error ("Cell (" + RowIndex + ", " + ColumnId + ") could not be selected.");
}

function GetNestedTable (Grid, TableOrGroup, RowIndex, TableId)
{
  // Get the root table if no table is specified
  if (TableOrGroup == null)
    TableOrGroup = Grid.Table.TopLevelGroup;

  // Get the nested tables collection
  var NestedTables = TableOrGroup.Records.Item_2(RowIndex).NestedTables;

  // Check if the table is specified by caption or index
  if (aqObject.GetVarType (TableId) == varOleStr)
    return NestedTables.Item_2(TableId).ChildTable
  else
    return NestedTables.Item(TableId).ChildTable;
}

function GetRecord (Grid, TableOrGroup, RowIndex)
{
  // Get the root table if no table is specified
  if (TableOrGroup == null)
    TableOrGroup = Grid.Table.TopLevelGroup;

  return TableOrGroup.Records.Item_2(RowIndex);
}

function GetColumn (Grid, Table, ColumnId)
{
  var Columns, ColDescriptor, i;

  // Get the table columns
  if (Table == null)
    Columns = Grid.TableDescriptor.Columns
  else
    Columns = Table.ParentTableDescriptor.Columns;

  if (aqObject.GetVarType (ColumnId) == varOleStr)
  // The column is specified by its caption
  {
    // Search for the desired column
    for (i=0; i<Columns.Count; i++)
    {
      ColDescriptor = Columns.Item(i);
      if (ColDescriptor.HeaderText.OleValue == ColumnId)
        return ColDescriptor; // Column is found
    }
  return null; // Column is not found
  }
  else
    // The column is specified by its index
    return Columns.Item(ColumnId);
}

Python

def Main ():

  # Obtain the grid object
  p = Sys.Process("EmployeeTerritoryOrder")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")

  # Select the cell in the root table
  SelectCell (Grid, None, 0, "FirstName")
  aqUtils.Delay (1000)
  # Select the cell in the nested table
  Table = GetNestedTable (Grid, None, 0, "Orders")
  SelectCell (Grid, Table, 10, "OrderDate")

def SelectCell (Grid, TableOrGroup, RowIndex, ColumnId):
  # Get the data row object and the column field name
  Rec = GetRecord (Grid, TableOrGroup, RowIndex)
  FieldName = GetColumn (Grid, TableOrGroup, ColumnId).MappingName

  # Select the cell and check if it was selected
  if not Rec.SetCurrent_2 (FieldName):
    Log.Error ("Cell (" + RowIndex + ", " + ColumnId + ") could not be selected.")

def GetNestedTable (Grid, TableOrGroup, RowIndex, TableId):
  # Get the root table if no table is specified
  if (TableOrGroup == None):
    TableOrGroup = Grid.Table.TopLevelGroup

  # Get the nested tables collection
  NestedTables = TableOrGroup.Records.Item_2[RowIndex].NestedTables

  # Check if the table is specified by caption or index
  if (aqObject.GetVarType (TableId) == varOleStr):
    return NestedTables.Item_2[TableId].ChildTable
  else:
    return NestedTables.Item[TableId].ChildTable

def GetRecord (Grid, TableOrGroup, RowIndex):
  # Get the root table if no table is specified
  if (TableOrGroup == None):
    TableOrGroup = Grid.Table.TopLevelGroup

  return TableOrGroup.Records.Item_2[RowIndex]

def GetColumn (Grid, Table, ColumnId):

  # Get the table columns
  if (Table == None):
    Columns = Grid.TableDescriptor.Columns
  else:
    Columns = Table.ParentTableDescriptor.Columns

  if (aqObject.GetVarType (ColumnId) == varOleStr):
  # The column is specified by its caption
    # Search for the desired column
    for i in range(0, Columns.Count-1):
      ColDescriptor = Columns.Item[i]
      if (ColDescriptor.HeaderText.OleValue == ColumnId):
        return ColDescriptor # Column is found
    return None # Column is not found
  else:
    # The column is specified by its index
    return Columns.Item(ColumnId)

VBScript

Sub Main
  Dim p, Grid, Table

  ' Obtain the grid object
  Set p = Sys.Process("EmployeeTerritoryOrder")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")

  ' Select the cell in the root table
  Call SelectCell (Grid, Nothing, 0, "FirstName")
  Call aqUtils.Delay (1000)
  ' Select the cell in the nested table
  Set Table = GetNestedTable (Grid, Nothing, 0, "Orders")
  Call SelectCell (Grid, Table, 10, "OrderDate")
End Sub

Sub SelectCell (Grid, TableOrGroup, RecIndex, ColumnId)
  Dim Rec, FieldName

  ' Get the data row object and the column field name
  Set Rec = GetRecord (Grid, TableOrGroup, RecIndex)
  Set FieldName = GetColumn (Grid, TableOrGroup, ColumnId).MappingName

  ' Select the cell and check if it was selected
  If Not Rec.SetCurrent_2 (FieldName) Then
    Call Log.Error ("Cell (" & RecIndex & ", " & ColumnId & ") could not be selected.")
  End If
End Sub

Function GetNestedTable (Grid, TableOrGroup, RowIndex, TableId)
  Dim NestedTables

  ' Get the root table if no table is specified
  If TableOrGroup Is Nothing Then
    Set TableOrGroup = Grid.Table.TopLevelGroup
  End If

  ' Get the nested tables collection
  Set NestedTables = TableOrGroup.Records.Item_2(RowIndex).NestedTables

  ' Check if the table is specified by caption or index
  If aqObject.GetVarType (TableId) = varOleStr Then
    Set GetNestedTable = NestedTables.Item_2(TableId).ChildTable
  Else
    Set GetNestedTable = NestedTables.Item(TableId).ChildTable
  End If
End Function

Function GetRecord (Grid, TableOrGroup, RowIndex)
  ' Get the root table if no table is specified
  If TableOrGroup Is Nothing Then
    Set TableOrGroup = Grid.Table.TopLevelGroup
  End If

  Set GetRecord = TableOrGroup.Records.Item_2(RowIndex)
End Function

Function GetColumn (Grid, Table, ColumnId)
  Dim Columns, ColDescriptor, i

  ' Get the table columns
  If Table Is Nothing Then
    Set Columns = Grid.TableDescriptor.Columns
  Else
    Set Columns = Table.ParentTableDescriptor.Columns
  End If

  If aqObject.GetVarType (ColumnId) = varOleStr Then
    ' The column is specified by its caption
    ' Search for the desired column
    For i=0 To Columns.Count-1
      Set ColDescriptor = Columns.Item(i)
      If ColDescriptor.HeaderText.OleValue = ColumnId Then
        Set GetColumn = ColDescriptor ' Column is found
        Exit Function
      End If
    Next
    Set GetColumn = Nothing ' Column is not found
  Else
    ' The column is specified by its index
    Set GetColumn = Columns.Item(ColumnId)
  End If
End Function

DelphiScript

procedure SelectCell (Grid, TableOrGroup, RecIndex, ColumnId); forward;
function GetNestedTable (Grid, TableOrGroup, RowIndex, TableId); forward;
function GetRecord (Grid, TableOrGroup, RowIndex); forward;
function GetColumn (Grid, Table, ColumnId); forward;

procedure TestSelectCell;
var p, Grid, Table : OleVariant;
begin
  // Obtain the grid object
  p := Sys.WaitProcess('EmployeeTerritoryOrder', 10000);
  Grid := p.WinFormsObject('Form1').WinFormsObject('gridGroupingControl1');

  // Select the cell in the root table
  SelectCell (Grid, nil, 0, 'FirstName');
  aqUtils.Delay (1000);
  // Select the cell in the nested table
  Table := GetNestedTable (Grid, nil, 0, 'Orders');
  SelectCell (Grid, Table, 10, 'OrderDate');
end;

procedure SelectCell (Grid, TableOrGroup, RecIndex, ColumnId);
var Rec, FieldName;
begin
  // Get the data row object and the column field name
  Rec := GetRecord (Grid, TableOrGroup, RecIndex);
  FieldName := GetColumn (Grid, TableOrGroup, ColumnId).MappingName;

  // Select the cell and check if it was selected
  if not Rec.SetCurrent_2 (FieldName) then
    Log.Error ('Cell (' + aqConvert.VarToStr(RecIndex) + ', ' + aqConvert.VarToStr(ColumnId) + ') could not be selected.');
end;

function GetNestedTable (Grid, TableOrGroup, RowIndex, TableId);
var NestedTables : OleVariant;
begin
  // Get the root table if no table is specified
  if TableOrGroup = nil then
    TableOrGroup := Grid.Table.TopLevelGroup;

  // Get the nested tables collection
  NestedTables := TableOrGroup.Records.Item_2[RowIndex].NestedTables;

  // Check if the table is specified by caption or index
  if aqObject.GetVarType (TableId) = varOleStr then
    Result := NestedTables.Item_2[TableId].ChildTable
  else
    Result := NestedTables.Item[TableId].ChildTable;
end;

function GetRecord (Grid, TableOrGroup, RowIndex);
begin
  // Get the root table if no table is specified
  if TableOrGroup = nil then
    TableOrGroup := Grid.Table.TopLevelGroup;

  Result := TableOrGroup.Records.Item_2[RowIndex];
end;

function GetColumn (Grid, Table, ColumnId);
var Columns, ColDescriptor, i : OleVariant;
begin
  // Get the table columns
  if Table = nil then
    Columns := Grid.TableDescriptor.Columns
  else
    Columns := Table.ParentTableDescriptor.Columns;

  if aqObject.GetVarType (ColumnId) = varOleStr then
  // The column is specified by its caption
  begin
    // Search for the desired column
    for i:=0 to Columns.Count-1 do
    begin
      ColDescriptor := Columns.Item[i];
      if ColDescriptor.HeaderText.OleValue = ColumnId then
      begin
        Result := ColDescriptor; // Column is found
        Exit;
      end
    end;
    Result := nil; // Column is not found
  end
  else
    // The column is specified by its index
    Result := Columns.Item[ColumnId];
end;

C++Script, C#Script

function Main ()
{
  var p, Grid, Table;

  // Obtain the grid object
  p = Sys["WaitProcess"]("EmployeeTerritoryOrder", 10000);
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridGroupingControl1");

  // Select the cell in the root table
  SelectCell (Grid, null, 0, "FirstName");
  aqUtils["Delay"] (1000);
  // Select the cell in the nested table
  Table = GetNestedTable (Grid, null, 0, "Orders");
  SelectCell (Grid, Table, 10, "OrderDate");
}

function SelectCell (Grid, TableOrGroup, RowIndex, ColumnId)
{
  // Get the data row object and the column's field name
  var Rec = GetRecord (Grid, TableOrGroup, RowIndex);
  var FieldName = GetColumn (Grid, TableOrGroup, ColumnId)["MappingName"];

  // Select the cell and check if it was selected
  if (!Rec["SetCurrent_2"](FieldName))
    Log["Error"]("Cell (" + RowIndex + ", " + ColumnId + ") could not be selected.");
}

function GetNestedTable (Grid, TableOrGroup, RowIndex, TableId)
{
  // Get the root table if no table is specified
  if (TableOrGroup == null)
    TableOrGroup = Grid["Table"]["TopLevelGroup"];

  // Get the nested tables collection
  var NestedTables = TableOrGroup["Records"]["Item_2"](RowIndex)["NestedTables"];

  // Check if the table is specified by caption or index
  if (aqObject["GetVarType"] (TableId) == varOleStr)
    return NestedTables["Item_2"](TableId)["ChildTable"]
  else
    return NestedTables["Item"](TableId)["ChildTable"];
}

function GetRecord (Grid, TableOrGroup, RowIndex)
{
  // Get the root table if no table is specified
  if (TableOrGroup == null)
    TableOrGroup = Grid["Table"]["TopLevelGroup"];

  return TableOrGroup["Records"]["Item_2"](RowIndex);
}

function GetColumn (Grid, Table, ColumnId)
{
  var Columns, ColDescriptor, i;

  // Get the table columns
  if (Table == null)
    Columns = Grid["TableDescriptor"]["Columns"]
  else
    Columns = Table["ParentTableDescriptor"]["Columns"];

  if (aqObject["GetVarType"] (ColumnId) == varOleStr)
  // The column is specified by its caption
  {
    // Search for the desired column
    for (i=0; i<Columns["Count"]; i++)
    {
      ColDescriptor = Columns["Item"](i);
      if (ColDescriptor["HeaderText"]["OleValue"] == ColumnId)
        return ColDescriptor; // Column is found
    }
  return null; // Column is not found
  }
  else
    // The column is specified by its index
    return Columns["Item"](ColumnId);
}

See Also

Working With Syncfusion GridGroupingControl
ClickCell Action (Grid Controls)
Getting the Focused Row, Column and Cell in Syncfusion GridGroupingControl
Obtaining and Setting Cell Values in Syncfusion GridGroupingControl

Highlight search results