Obtaining and Setting Cell Values in Syncfusion GridGroupingControl

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

This topic describes the various approaches that you can use to obtain and change values stored in the GridGroupingControl cells. Note that before getting or setting the cell value, you need to know in which row and column the desired cell resides. For example, you can search for the record containing the desired cell within the grid.

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.

Obtaining Cell Values

To get the value from a particular grid cell, you can use the wValue property of the SyncfusionEssGrid or SyncfusionEssGridView object. Note that this property returns the “native” .NET object corresponding to the cell value. Some “simple” values, for example, Integer, Boolean and others, are OLE-compatible and thus can be used in scripts directly. Others, such as String, Decimal, DateTime and enumeration values are made OLE-compatible via the OleValue property added to these objects by TestComplete. To work with complex object values, use their internal properties and methods.

Below is an example that demonstrates how you can obtain values from GridGroupingControl cells.

JavaScript, JScript

function Main ()
{
  var p, Grid, ChildTable, CellValue;
   
  // Obtain the grid object and the nested table
  p = Sys.Process("EmployeeTerritoryOrder");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1");
  ChildTable = Grid.wChildView(0, "Orders");

  // Get the cell value
  CellValue = ChildTable.wValue(0, "OrderDate");
  // Get an Ole-compatible value using the OleValue property
  Log.Message ("Cell value: " + aqConvert.VarToStr(CellValue.OleValue));
  // Work with the cell value using its internal properties
  Log.Message ("Year: " + CellValue.Year);
  Log.Message ("Month: " + CellValue.Month);
  Log.Message ("Day: " + CellValue.Day);
}

Python

def Main ():
   
  # Obtain the grid object and the nested table
  p = Sys.Process("EmployeeTerritoryOrder")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")
  ChildTable = Grid.wChildView(0, "Orders")

  # Get the cell value
  CellValue = ChildTable.wValue(0, "OrderDate")
  # Get an Ole-compatible value using the OleValue property
  Log.Message ("Cell value: " + aqConvert.VarToStr(CellValue.OleValue))
  # Work with the cell value using its internal properties
  Log.Message ("Year: " + CellValue.Year)
  Log.Message ("Month: " + CellValue.Month)
  Log.Message ("Day: " + CellValue.Day)

VBScript

Sub Main
  Dim p, Grid, ChildTable, CellValue

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

  ' Get the cell value
  Set CellValue = ChildTable.wValue(0, "OrderDate")
  ' Get an Ole-compatible value using the OleValue property
  Log.Message ("Cell value: " & aqConvert.VarToStr(CellValue.OleValue))
  ' Work with the cell value using its internal properties
  Log.Message ("Year: " & CellValue.Year)
  Log.Message ("Month: " & CellValue.Month)
  Log.Message ("Day: " & CellValue.Day)
End Sub

DelphiScript

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

  // Get the cell value
  CellValue := ChildTable.wValue[0, 'OrderDate'];
  // Get an Ole-compatible value using the OleValue property
  Log.Message ('Cell value: ' + aqConvert.VarToStr(CellValue.OleValue));
  // Work with the cell value using its internal properties
  Log.Message ('Year: ' + aqConvert.VarToStr(CellValue.Year));
  Log.Message ('Month: ' + aqConvert.VarToStr(CellValue.Month));
  Log.Message ('Day: ' + aqConvert.VarToStr(CellValue.Day));
end;

C++Script, C#Script

function Main ()
{
  var p, Grid, ChildTable, CellValue;
   
  // Obtain the grid object and the nested table
  p = Sys["Process"]("EmployeeTerritoryOrder");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridGroupingControl1");
  ChildTable = Grid["wChildView"](0, "Orders");

  // Get the cell value
  CellValue = ChildTable["wValue"](0, "OrderDate");
  // Get an Ole-compatible value using the OleValue property
  Log["Message"]("Cell value: " + aqConvert["VarToStr"](CellValue["OleValue"]));
  // Work with the cell value using its internal properties
  Log["Message"]("Year: " + CellValue["Year"]);
  Log["Message"]("Month: " + CellValue["Month"]);
  Log["Message"]("Day: " + CellValue["Day"]);
}

Setting Cell Values

There are two general approaches for modifying GridGroupingControl cell values:

  • Simulating the user actions over the grid cell’s in-place editor, for example, “typing” the new value into the cell.
  • Assigning the new value using the wValue property of the SyncfusionEssGrid or SyncfusionEssGridView object.

Detailed information and script samples for both approaches are provided below. These approaches work well for most types of in-place editors. However, modifying the cell value programmatically using the wValue property does not involve any user interaction with the grid control and thus will not trigger the corresponding events. That is why you may find that simulating user actions over the grid is more suitable to your needs.

Simulating User Input

To modify grid cell values, you can input the new values directly in grid cells. Note that before that, you should locate the row and column in which the cell resides. For example, you can search for the row containing the cell with the desired value. After you have determined the cell position, you should select the desired cell within the grid and activate the cell’s in-place editor. When the cell’s is in the edit mode, you can “type” the desired value into it using the Keys action applied to the grid control.

Below is an example that illustrates how you can do it. It “types” new values into grid cells.

Example

View description

JavaScript

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

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

  // Input new values
  InputCellValue (Grid, ChildTable, 0, "OrderDate", "4/1/2007 10:00 AM");
  InputCellValue (Grid, ChildTable, 0, "RequiredDate", "4/25/2007 10:00 AM");
  InputCellValue (Grid, ChildTable, 0, "ShippedDate", "4/20/2007 10:00 AM");
  InputCellValue (Grid, ChildTable, 0, "ShipName", "Bon app'");
}

function InputCellValue (Grid, View, RowIndex, ColumnId, Text)
{
  // Select the cell and activate its in-place editor
  if (strictEqual(View, null))
    Grid.ClickCell (RowIndex, ColumnId)
  else
    View.ClickCell (RowIndex, ColumnId);
  ActivateCellEditor (Grid);
  // Delete the previous value and type the new one
  Grid.Keys ("[Home]![End][Del]" + Text);
  // Save the changes
  CloseCellEditor (Grid);
}

function ActivateCellEditor (Grid)
{
  if (! Grid.TableControl.GetNestedCurrentCell().IsEditing)
    Grid.Keys ("[F2]")
}

function CloseCellEditor (Grid)
{
  Grid.Keys ("[Enter]");
}

JScript

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

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

  // Input new values
  InputCellValue (Grid, ChildTable, 0, "OrderDate", "4/1/2007 10:00 AM");
  InputCellValue (Grid, ChildTable, 0, "RequiredDate", "4/25/2007 10:00 AM");
  InputCellValue (Grid, ChildTable, 0, "ShippedDate", "4/20/2007 10:00 AM");
  InputCellValue (Grid, ChildTable, 0, "ShipName", "Bon app'");
}

function InputCellValue (Grid, View, RowIndex, ColumnId, Text)
{
  // Select the cell and activate its in-place editor
  if (View == null)
    Grid.ClickCell (RowIndex, ColumnId)
  else
    View.ClickCell (RowIndex, ColumnId);
  ActivateCellEditor (Grid);
  // Delete the previous value and type the new one
  Grid.Keys ("[Home]![End][Del]" + Text);
  // Save the changes
  CloseCellEditor (Grid);
}

function ActivateCellEditor (Grid)
{
  if (! Grid.TableControl.GetNestedCurrentCell().IsEditing)
    Grid.Keys ("[F2]")
}

function CloseCellEditor (Grid)
{
  Grid.Keys ("[Enter]");
}

Python

def Main ():

  # Obtain the grid object and its child table
  p = Sys.Process("EmployeeTerritoryOrder")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")
  ChildTable = Grid.wChildView(0, "Orders")

  # Input new values
  InputCellValue (Grid, ChildTable, 0, "OrderDate", "4/1/2007 10:00 AM")
  InputCellValue (Grid, ChildTable, 0, "RequiredDate", "4/25/2007 10:00 AM")
  InputCellValue (Grid, ChildTable, 0, "ShippedDate", "4/20/2007 10:00 AM")
  InputCellValue (Grid, ChildTable, 0, "ShipName", "Bon app'")

def InputCellValue (Grid, View, RowIndex, ColumnId, Text):
  # Select the cell and activate its in-place editor
  if (View == None):
    Grid.ClickCell (RowIndex, ColumnId)
  else:
    View.ClickCell (RowIndex, ColumnId)
  ActivateCellEditor (Grid)
  # Delete the previous value and type the new one
  Grid.Keys ("[Home]![End][Del]" + Text)
  # Save the changes
  CloseCellEditor (Grid)

def ActivateCellEditor (Grid):
  if not Grid.TableControl.GetNestedCurrentCell().IsEditing:
    Grid.Keys ("[F2]")

def CloseCellEditor (Grid):
  Grid.Keys ("[Enter]")

VBScript

Sub Main
  Dim p, Grid, ChildTable
   
  ' Obtain the grid object and its child table
  Set p = Sys.Process("EmployeeTerritoryOrder")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")
  Set ChildTable = Grid.wChildView(0, "Orders")

  ' Modify the cells' values themselves
  Call InputCellValue (Grid, ChildTable, 0, "OrderDate", "4/1/2007 10:00 AM")
  Call InputCellValue (Grid, ChildTable, 0, "RequiredDate", "4/25/2007 10:00 AM")
  Call InputCellValue (Grid, ChildTable, 0, "ShippedDate", "4/20/2007 10:00 AM")
  Call InputCellValue (Grid, ChildTable, 0, "ShipName", "Bon app'")
End Sub

Sub InputCellValue (Grid, View, RowIndex, ColumnId, Text)
  ' Select the cell and activate its in-place editor
  If View Is Nothing Then
    Call Grid.ClickCell (RowIndex, ColumnId)
  Else
    Call View.ClickCell (RowIndex, ColumnId)
  End If
  ActivateCellEditor (Grid)
  ' Delete the previous value and type the new one
  Grid.Keys ("[Home]![End][Del]" & Text)
  ' Save the changes
  CloseCellEditor (Grid)
End Sub

Sub ActivateCellEditor (Grid)
  If Not Grid.TableControl.GetNestedCurrentCell.IsEditing Then
    Grid.Keys "[F2]"
  End If
End Sub

Sub CloseCellEditor (Grid)
  Grid.Keys "[Enter]"
End Sub

DelphiScript

procedure InputCellValue (Grid, View, RowIndex, ColumnId, Text); forward;
procedure ActivateCellEditor (Grid); forward;
procedure CloseCellEditor (Grid); forward;

procedure Main;
var p, Grid, ChildTable : OleVariant;
begin
  // Obtain the grid object and its child table
  p := Sys.Process('EmployeeTerritoryOrder');
  Grid := p.WinFormsObject('Form1').WinFormsObject('gridGroupingControl1');
  ChildTable := Grid.wChildView(0, 'Orders');

  // Modify the cells' values themselves
  InputCellValue (Grid, ChildTable, 0, 'OrderDate', '4/1/2007 10:00 AM');
  InputCellValue (Grid, ChildTable, 0, 'RequiredDate', '4/25/2007 10:00 AM');
  InputCellValue (Grid, ChildTable, 0, 'ShippedDate', '4/20/2007 10:00 AM');
  InputCellValue (Grid, ChildTable, 0, 'ShipName', 'Bon app''');
end;

procedure InputCellValue (Grid, View, RowIndex, ColumnId, Text);
begin
  // Select the cell and activate its in-place editor
  if View = nil then
    Grid.ClickCell (RowIndex, ColumnId)
  else
    View.ClickCell (RowIndex, ColumnId);
  ActivateCellEditor (Grid);
  // Delete the previous value and type the new one
  Grid.Keys ('[Home]![End][Del]' + Text);
  // Save the changes
  CloseCellEditor (Grid);
end;

procedure ActivateCellEditor (Grid);
begin
  if not Grid.TableControl.GetNestedCurrentCell.IsEditing then
    Grid.Keys ('[F2]')
end;

procedure CloseCellEditor (Grid);
begin
  Grid.Keys ('[Enter]');
end;

C++Script, C#Script

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

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

  // Input new values
  InputCellValue (Grid, ChildTable, 0, "OrderDate", "4/1/2007 10:00 AM");
  InputCellValue (Grid, ChildTable, 0, "RequiredDate", "4/25/2007 10:00 AM");
  InputCellValue (Grid, ChildTable, 0, "ShippedDate", "4/20/2007 10:00 AM");
  InputCellValue (Grid, ChildTable, 0, "ShipName", "Bon app'");
}

function InputCellValue (Grid, View, RowIndex, ColumnId, Text)
{
  // Select the cell and activate its in-place editor
  if (View == null)
    Grid["ClickCell"](RowIndex, ColumnId)
  else
    View["ClickCell"](RowIndex, ColumnId);
  ActivateCellEditor (Grid);
  // Delete the previous value and type the new one
  Grid["Keys"]("[Home]![End][Del]" + Text);
  // Save the changes
  CloseCellEditor (Grid);
}

function ActivateCellEditor (Grid)
{
  if (! Grid["TableControl"]["GetNestedCurrentCell"]()["IsEditing"])
    Grid["Keys"]("[F2]")
}

function CloseCellEditor (Grid)
{
  Grid["Keys"]("[Enter]");
}

The GridGrouping control may contain cells with drop-down buttons that are used to invoke popup editors. To learn how you can “press” these buttons from scripts and work with popup editors, see Clicking In-place Editors' Buttons in Syncfusion GridGroupingControl.

A possible alternative to typing data into the cell is to paste it from the clipboard. For more information on how to do this, see Copying and Pasting Cell Values in Syncfusion GridGroupingControl.

Assigning the New Value Programmatically

Another way to modify grid cell values is to use the wValue property of the SyncfusionEssGrid or object. This property is read-write, so it can be used to obtain grid cell values as well as to change them.

The following example uses a helper CreateDateTime function to create a new instance of the .NET System.DateTime class with the specified year, month, day, hour, minute and seconds. In order for this function to run successfully, the .NET Classes Support plugin must be installed and enabled.

JavaScript

function Main ()
{
  var p, Grid, ChildTable;
   
  // Obtain the grid object and its child table
  p = Sys.Process("EmployeeTerritoryOrder");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1");
  ChildTable = Grid.wChildView (0, "Orders");

  // Modify the cells' values
  ChildTable.$set("wValue", 0, "OrderDate", CreateDateTime (2007, 4, 25, 10, 0, 0));
  ChildTable.$set("wValue", 0, "ShipName", "Bon app'");
  ChildTable.$set("wValue", 0, "Freight", 166.31);
}

function CreateDateTime (Year, Month, Day, Hour, Minute, Second)
{
  return dotNET.System.DateTime.zctor_5(Year, Month, Day, Hour, Minute, Second);
}

JScript

function Main ()
{
  var p, Grid, ChildTable;
   
  // Obtain the grid object and its child table
  p = Sys.Process("EmployeeTerritoryOrder");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1");
  ChildTable = Grid.wChildView (0, "Orders");

  // Modify the cells' values
  ChildTable.wValue(0, "OrderDate") = CreateDateTime (2007, 4, 25, 10, 0, 0);
  ChildTable.wValue(0, "ShipName") = "Bon app'";
  ChildTable.wValue(0, "Freight") = 166.31;
}

function CreateDateTime (Year, Month, Day, Hour, Minute, Second)
{
  return dotNET.System.DateTime.zctor_5(Year, Month, Day, Hour, Minute, Second);
}

Python

def Main ():
   
  # Obtain the grid object and its child table
  p = Sys.Process("EmployeeTerritoryOrder")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridGroupingControl1")
  ChildTable = Grid.wChildView (0, "Orders")

  # Modify the cells' values
  ChildTable.wValue[0, "OrderDate"] = CreateDateTime (2007, 4, 25, 10, 0, 0)
  ChildTable.wValue[0, "ShipName"] = "Bon app'"
  ChildTable.wValue[0, "Freight"] = 166.31

def CreateDateTime (Year, Month, Day, Hour, Minute, Second):
  return dotNET.System.DateTime.zctor_5(Year, Month, Day, Hour, Minute, Second)

VBScript

Sub Main
  Dim p, Grid, ChildTable

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

  ' Modify the cells' values themselves
  ChildTable.wValue(0, "OrderDate") = CreateDateTime (2007, 4, 25, 10, 0, 0)
  ChildTable.wValue(0, "ShipName") = "Bon app'"
  ChildTable.wValue(0, "Freight") = 166.31
End Sub

Function CreateDateTime (Year, Month, Day, Hour, Minute, Second)
  Set CreateDateTime = dotNET.System.DateTime.zctor_5(Year, Month, Day, Hour, Minute, Second)
End Function

DelphiScript

function CreateDateTime (Year, Month, Day, Hour, Minute, Second);
begin
  Result := dotNET.System.DateTime.zctor_5(Year, Month, Day, Hour, Minute, Second);
end;

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

  // Modify the cells' values themselves
  ChildTable.wValue[0, 'OrderDate'] := CreateDateTime (2007, 4, 25, 10, 0, 0);
  ChildTable.wValue[0, 'ShipName'] := 'Bon app''';
  ChildTable.wValue[0, 'Freight'] := 166.31;
end;

C++Script, C#Script

function Main ()
{
  var p, Grid, ChildTable;
   
  // Obtain the grid object and its child table
  p = Sys["Process"]("EmployeeTerritoryOrder");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridGroupingControl1");
  ChildTable = Grid["wChildView"](0, "Orders");

  // Modify the cells' values
  ChildTable["wValue"](0, "OrderDate") = CreateDateTime (2007, 4, 25, 10, 0, 0);
  ChildTable["wValue"](0, "ShipName") = "Bon app'";
  ChildTable["wValue"](0, "Freight") = 166.31;
}

function CreateDateTime (Year, Month, Day, Hour, Minute, Second)
{
  return dotNET["System"]["DateTime"]["zctor_5"](Year, Month, Day, Hour, Minute, Second);
}

See Also

Working With Syncfusion GridGroupingControl
wValue Property (Grid Controls)
Selecting Cells in Syncfusion GridGroupingControl
Activating and Closing In-place Editors in Syncfusion GridGroupingControl
Clicking In-place Editors' Buttons in Syncfusion GridGroupingControl
Copying and Pasting Cell Values in Syncfusion GridGroupingControl

Highlight search results