Searching for Records in Syncfusion GridGroupingControl

Applies to TestComplete 14.60, last modified on April 22, 2021

In order to perform various actions over the GridGroupingControl control, you first need to locate the row that contains the data that you are going to work with. You may also need to find a certain record to make sure that data has been loaded into the grid correctly, and so on. This topic describes how you can search for records in the GridGroupingControl.

GridGroupingControl does not have built-in methods for searching in the grid, so you will need to implement the search algorithm yourself. A general search approach implies that you iterate through grid rows and on each iteration check whether the current row matches the search condition, for example, if it contains the sought-for value or has a specific set of options.

Note that the grid control may display the data with special formatting, so the actual value of a particular cell can be significantly different from the cell’s display text. The grid can also contain columns that use lookup combo boxes to display values different from the ones that are actually stored in the column cells. You should keep this in mind when specifying the sought-for values for your search procedure.

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.

The following example demonstrates how you can locate a grid row by its value in a particular column.

Example

View description

JavaScript, JScript

function Main ()
{
  var p, Grid, ChildTable, RowIndex, SearchValue;

  // Obtain the grid object
  p = Sys.Process("EmployeeTerritoryOrder");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1");
  ChildTable = Grid.wChildView (0, "Orders");

  // Locate a row
  SearchValue = 10400;
  RowIndex = FindRow (ChildTable, "OrderID", SearchValue);
  if (RowIndex != -1)
    ChildTable.ClickCell (RowIndex, "OrderID")
  else
    Log.Error ("Row with cell value " + SearchValue + " was not found.");

  // Locate a row by a complex value
  SearchValue = CreateDateTime (1996, 10, 29, 8, 0, 0);
  RowIndex = FindRow (ChildTable, "OrderDate", SearchValue);
  if (RowIndex != -1)
    ChildTable.ClickCell (RowIndex, "OrderDate")
  else
    Log.Error ("Row with cell value " + SearchValue.ToString().OleValue + " was not found.");
}

function FindRow (ViewOrGroup, ColumnId, Value)
{
  for (var i=0; i<ViewOrGroup.wRowCount; i++)
    if (ViewOrGroup.wValue(i, ColumnId).Equals(Value))
      return i;

  return -1;
}

function CreateDateTime (Year, Month, Day, Hour, Minute, Second)
{
  return Sys.Process("EmployeeTerritoryOrder").AppDomain("EmployeeTerritoryOrder.exe").dotNET.System.DateTime.zctor_5(Year, Month, Day, Hour, Minute, Second);
}

Python

def Main ():

  # Obtain the grid object
  p = Sys.Process("EmployeeTerritoryOrder")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")
  ChildTable = Grid.wChildView [0, "Orders"]

  # Locate a row
  SearchValue = 10400
  RowIndex = FindRow (ChildTable, "OrderID", SearchValue)
  if (RowIndex != -1):
    ChildTable.ClickCell (RowIndex, "OrderID")
  else:
    Log.Error ("Row with cell value " + SearchValue + " was not found.")

  # Locate a row by a complex value
  SearchValue = CreateDateTime (1996, 10, 29, 8, 0, 0)
  RowIndex = FindRow (ChildTable, "OrderDate", SearchValue)
  if (RowIndex != -1):
    ChildTable.ClickCell (RowIndex, "OrderDate")
  else:
    Log.Error ("Row with cell value " + SearchValue.ToString().OleValue + " was not found.")

def FindRow (ViewOrGroup, ColumnId, Value):
  for i in range(0, ViewOrGroup.wRowCount-1):
    if (ViewOrGroup.wValue[i, ColumnId].Equals(Value)):
      return i

  return -1

def CreateDateTime (Year, Month, Day, Hour, Minute, Second):
  return Sys.Process("EmployeeTerritoryOrder").AppDomain("EmployeeTerritoryOrder.exe").dotNET.System.DateTime.zctor_5(Year, Month, Day, Hour, Minute, Second)

VBScript

Sub Main
  Dim p, Grid, ChildTable, RowIndex, SearchValue

  ' Obtain the grid object
  Set p = Sys.Process("EmployeeTerritoryOrder")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")
  Set ChildTable = Grid.wChildView (0, "Orders")

  ' Locate a row
  SearchValue = CLng(10400) ' Convert a 16-bit integer value to a 32-bit value
  RowIndex = FindRow (ChildTable, "OrderID", SearchValue)
  If RowIndex <> -1 Then
    Call ChildTable.ClickCell (RowIndex, "OrderID")
  Else
    Log.Error ("Row with cell value " & SearchValue & " was not found.")
  End If

  ' Locate a row by a complex value
  Set SearchValue = CreateDateTime (1996, 10, 29, 8, 0, 0)
  RowIndex = FindRow (ChildTable, "OrderDate", SearchValue)
  If RowIndex <> -1 Then
    Call ChildTable.ClickCell (RowIndex, "OrderDate")
  Else
    Log.Error ("Row with cell value " & SearchValue.ToString.OleValue & " was not found.")
  End If
End Sub

Function FindRow (ViewOrGroup, ColumnId, Value)
  Dim i
  For i = 0 To ViewOrGroup.wRowCount-1
    If ViewOrGroup.wValue(i, ColumnId).Equals(Value) Then
      FindRow = i
      Exit Function
    End If
  Next

  FindRow = -1
End Function

Function CreateDateTime (Year, Month, Day, Hour, Minute, Second)
  Set CreateDateTime = Sys.Process("EmployeeTerritoryOrder").AppDomain("EmployeeTerritoryOrder.exe").dotNET.System.DateTime.zctor_5(Year, Month, Day, Hour, Minute, Second)
End Function

DelphiScript

function FindRow (ViewOrGroup, ColumnId, Value); forward;
function CreateDateTime (Year, Month, Day, Hour, Minute, Second); forward;

procedure Main;
var p, Grid, ChildTable, RowIndex, SearchValue : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('EmployeeTerritoryOrder');
  Grid := p.WinFormsObject('Form1').WinFormsObject('gridGroupingControl1');
  ChildTable := Grid.wChildView[0, 'Orders'];

  // Locate a row
  SearchValue := 10400;
  RowIndex := FindRow (ChildTable, 'OrderID', SearchValue);
  if RowIndex <> -1 then
    ChildTable.ClickCell (RowIndex, 'OrderID')
  else
    Log.Error ('Row with cell value ' + aqConvert.VarToStr(SearchValue) + ' was not found.');

  // Locate a row by a complex value
  SearchValue := CreateDateTime (1996, 10, 29, 8, 0, 0);
  RowIndex := FindRow (ChildTable, 'OrderDate', SearchValue);
  if RowIndex <> -1 then
    ChildTable.ClickCell (RowIndex, 'OrderDate')
  else
    Log.Error ('Row with cell value ' + SearchValue.ToString.OleValue + ' was not found.');
end;

function FindRow (ViewOrGroup, ColumnId, Value);
var i : OleVariant;
begin
  for i := 0 to ViewOrGroup.wRowCount-1 do
    if ViewOrGroup.wValue[i, ColumnId].Equals(Value) then
    begin
      Result := i;
      Exit;
    end;

  Result := -1;
end;

function CreateDateTime (Year, Month, Day, Hour, Minute, Second);
begin
  Result := Sys.Process('EmployeeTerritoryOrder').AppDomain('EmployeeTerritoryOrder.exe').dotNET.System.DateTime.zctor_5(Year, Month, Day, Hour, Minute, Second);
end;

C++Script, C#Script

function Main ()
{
  var p, Grid, ChildTable, RowIndex, SearchValue;

  // Obtain the grid object
  p = Sys["Process"]("EmployeeTerritoryOrder");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridGroupingControl1");
  ChildTable = Grid["wChildView"](0, "Orders");

  // Locate a row
  SearchValue = 10400;
  RowIndex = FindRow (ChildTable, "OrderID", SearchValue);
  if (RowIndex != -1)
    ChildTable["ClickCell"](RowIndex, "OrderID")
  else
    Log["Error"]("Row with cell value " + SearchValue + " was not found.");

  // Locate a row by a complex value
  SearchValue = CreateDateTime (1996, 10, 29, 8, 0, 0);
  RowIndex = FindRow (ChildTable, "OrderDate", SearchValue);
  if (RowIndex != -1)
    ChildTable["ClickCell"](RowIndex, "OrderDate")
  else
    Log["Error"]("Row with cell value " + SearchValue["ToString"]()["OleValue"] + " was not found.");
}

function FindRow (ViewOrGroup, ColumnId, Value)
{
  for (var i=0; i<ViewOrGroup["wRowCount"]; i++)
    if (ViewOrGroup["wValue"](i, ColumnId)["Equals"](Value))
      return i;

  return -1;
}

function CreateDateTime (Year, Month, Day, Hour, Minute, Second)
{
  return Sys["Process"]("EmployeeTerritoryOrder")["AppDomain"]("EmployeeTerritoryOrder.exe")["dotNET"]["System"]["DateTime"]["zctor_5"](Year, Month, Day, Hour, Minute, Second);
}

See Also

Working With Syncfusion GridGroupingControl
Obtaining and Setting Cell Values in Syncfusion GridGroupingControl
Iterating Through Rows in Syncfusion GridGroupingControl

Highlight search results