Getting the Focused Row, Column and Cell in Syncfusion GridGroupingControl

Applies to TestComplete 15.68, last modified on October 03, 2024

When testing an application that uses Syncfusion GridGroupingControl controls, you may need to know which row, column and cell are currently focused. For this purpose, you can use internal methods and properties of the GridGroupingControl object, which is illustrated in the example below. The example contains four sample functions that can help you identify the currently selected cell in the GridGroupingControl:

  • GetCurrentRowIndex - returns the zero-based index of the row that contains the selected cell.
  • GetCurrentColIndex - returns the zero-based index of the column that contains the selected cell.
  • GetCurrentColCaption - returns the caption of the column that contains the selected cell.
  • GetCurrentCellValue - returns the value in the currently selected cell.
Note: In order for these functions to run successfully, TestComplete should have access to internal methods, properties and object of the GridGroupingControl object. That is, the .NET Application Support plugin must be installed and enabled.

JavaScript, JScript

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

  Log.Message ("Current row index: " + GetCurrentRowIndex(Grid) );
  Log.Message ("Current column index: " + GetCurrentColIndex(Grid));
  Log.Message ("Current column caption: " + GetCurrentColCaption(Grid));
  Log.Message ("Current cell value: " + GetCurrentCellValue(Grid).ToString().OleValue);
}

function GetCurrentRowIndex (Grid)
{
  var CurrentCell = Grid.TableControl.GetNestedCurrentCell();
  var RowObj = CurrentCell.Renderer.StyleInfo.TableCellIdentity.DisplayElement.ParentRecord;

  return RowObj.ParentGroup.Records.IndexOf(RowObj);
}

function GetCurrentColIndex (Grid)
{
  var CurrentCell = Grid.TableControl.GetNestedCurrentCell();
  var ColumnObj = CurrentCell.Renderer.StyleInfo.TableCellIdentity.Column;

  return ColumnObj.Collection.IndexOf(ColumnObj);
}

function GetCurrentColCaption (Grid)
{
  var CurrentCell = Grid.TableControl.GetNestedCurrentCell();
  var ColumnObj = CurrentCell.Renderer.StyleInfo.TableCellIdentity.Column;

  return ColumnObj.HeaderText.OleValue;
}

function GetCurrentCellValue (Grid)
{
  var CurrentCell = Grid.TableControl.GetNestedCurrentCell();
  return CurrentCell.Renderer.StyleInfo.CellValue;
}

Python

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

  Log.Message ("Current row index: " + GetCurrentRowIndex(Grid) )
  Log.Message ("Current column index: " + GetCurrentColIndex(Grid))
  Log.Message ("Current column caption: " + GetCurrentColCaption(Grid))
  Log.Message ("Current cell value: " + GetCurrentCellValue(Grid).ToString().OleValue)

def GetCurrentRowIndex (Grid):
  CurrentCell = Grid.TableControl.GetNestedCurrentCell()
  RowObj = CurrentCell.Renderer.StyleInfo.TableCellIdentity.DisplayElement.ParentRecord

  return RowObj.ParentGroup.Records.IndexOf(RowObj)

def GetCurrentColIndex (Grid):
  CurrentCell = Grid.TableControl.GetNestedCurrentCell()
  ColumnObj = CurrentCell.Renderer.StyleInfo.TableCellIdentity.Column

  return ColumnObj.Collection.IndexOf(ColumnObj)

def GetCurrentColCaption (Grid):
  CurrentCell = Grid.TableControl.GetNestedCurrentCell()
  ColumnObj = CurrentCell.Renderer.StyleInfo.TableCellIdentity.Column

  return ColumnObj.HeaderText.OleValue

def GetCurrentCellValue (Grid):
  CurrentCell = Grid.TableControl.GetNestedCurrentCell()
  return CurrentCell.Renderer.StyleInfo.CellValue

VBScript

Sub Main ()

   Dim p, Grid
   ' Obtain the grid object
   Set p = Sys.Process("HierarchySample")
   Set Grid = p.WinFormsObject("Form1").WinFormsObject("groupingGrid1")

   Log.Message ("Current row index: " & GetCurrentRowIndex(Grid) )
   Log.Message ("Current column index: " & GetCurrentColIndex(Grid))
   Log.Message ("Current column caption: " & GetCurrentColCaption(Grid))
   Log.Message ("Current cell value: " & GetCurrentCellValue(Grid).ToString().OleValue)
End Sub

Function GetCurrentRowIndex (Grid)

   Set CurrentCell = Grid.TableControl.GetNestedCurrentCell
   Set RowObj = CurrentCell.Renderer.StyleInfo.TableCellIdentity.DisplayElement.ParentRecord

   Set GetCurrentRowIndex = RowObj.ParentGroup.Records.IndexOf(RowObj)
End Function

Function GetCurrentColIndex (Grid)
   Set CurrentCell = Grid.TableControl.GetNestedCurrentCell
   Set ColumnObj = CurrentCell.Renderer.StyleInfo.TableCellIdentity.Column

   Set GetCurrentColIndex = ColumnObj.Collection.IndexOf(ColumnObj)
End Function

Function GetCurrentColCaption (Grid)

   Set CurrentCell = Grid.TableControl.GetNestedCurrentCell
   Set ColumnObj = CurrentCell.Renderer.StyleInfo.TableCellIdentity.Column

   Set GetCurrentColCaption = ColumnObj.HeaderText.OleValue
End Function

Function GetCurrentCellValue (Grid)
   Set CurrentCell = Grid.TableControl.GetNestedCurrentCell
   Set GetCurrentCellValue = CurrentCell.Renderer.StyleInfo.CellValue
End Function

DelphiScript

procedure Main();
var p, Grid: oleVariant;
begin
   // Obtain the grid object
   p := Sys.Process('HierarchySample');
   Grid := p.WinFormsObject('Form1').WinFormsObject('groupingGrid1');

   Log.Message ('Current row index: ' + GetCurrentRowIndex(Grid) );
   Log.Message ('Current column index: ' + GetCurrentColIndex(Grid));
   Log.Message ('Current column caption: ' + GetCurrentColCaption(Grid));
   Log.Message ('Current cell value: ' + GetCurrentCellValue(Grid).ToString().OleValue);
end;

function GetCurrentRowIndex (Grid): oleVariant;
var CurrentCell, RowObj: oleVariant;
begin
   CurrentCell := Grid.TableControl.GetNestedCurrentCell;
   RowObj := CurrentCell.Renderer.StyleInfo.TableCellIdentity.DisplayElement.ParentRecord;

   Result := RowObj.ParentGroup.Records.IndexOf(RowObj);
end;

function GetCurrentColIndex (Grid): oleVariant;
var CurrentCell, ColumnObj: oleVariant;
begin
  CurrentCell := Grid.TableControl.GetNestedCurrentCell;
  ColumnObj := CurrentCell.Renderer.StyleInfo.TableCellIdentity.Column;

  Result := ColumnObj.Collection.IndexOf(ColumnObj);
end;

function GetCurrentColCaption (Grid): oleVariant;
var CurrentCell, ColumnObj: oleVariant;
begin
  CurrentCell := Grid.TableControl.GetNestedCurrentCell;
  ColumnObj := CurrentCell.Renderer.StyleInfo.TableCellIdentity.Column;

  Result := ColumnObj.HeaderText.OleValue;
end;

function GetCurrentCellValue (Grid): oleVariant;
var CurrentCell: oleVariant;
begin
  CurrentCell := Grid.TableControl.GetNestedCurrentCell;
  Result := CurrentCell.Renderer.StyleInfo.CellValue;
end;

C++Script, C#Script

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

  Log["Message"]("Current row index: " + GetCurrentRowIndex(Grid) );
  Log["Message"]("Current column index: " + GetCurrentColIndex(Grid));
  Log["Message"]("Current column caption: " + GetCurrentColCaption(Grid));
  Log["Message"]("Current cell value: " + GetCurrentCellValue(Grid)["ToString"]()["OleValue"]);
}

function GetCurrentRowIndex (Grid)
{
  var CurrentCell = Grid["TableControl"]["GetNestedCurrentCell"]();
  var RowObj = CurrentCell["Renderer"]["StyleInfo"]["TableCellIdentity"]["DisplayElement"]["ParentRecord"];

  return RowObj["ParentGroup"]["Records"]["IndexOf"](RowObj);
}

function GetCurrentColIndex (Grid)
{
  var CurrentCell = Grid["TableControl"]["GetNestedCurrentCell"]();
  var ColumnObj = CurrentCell["Renderer"]["StyleInfo"]["TableCellIdentity"]["Column"];

  return ColumnObj["Collection"]["IndexOf"](ColumnObj);
}

function GetCurrentColCaption (Grid)
{
  var CurrentCell = Grid["TableControl"]["GetNestedCurrentCell"]();
  var ColumnObj = CurrentCell["Renderer"]["StyleInfo"]["TableCellIdentity"]["Column"];

  return ColumnObj["HeaderText"]["OleValue"];
}

function GetCurrentCellValue (Grid)
{
  var CurrentCell = Grid["TableControl"]["GetNestedCurrentCell"]();
  return CurrentCell["Renderer"]["StyleInfo"]["CellValue"];
}

See Also

Working With Syncfusion GridGroupingControl
Selecting Cells in Syncfusion GridGroupingControl
Obtaining and Setting Cell Values in Syncfusion GridGroupingControl
Searching for Records in Syncfusion GridGroupingControl

Highlight search results