Activating and Closing In-place Editors in Syncfusion GridControl

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

Syncfusion GridControl lets users change data directly within the grid cells. To modify cell values, you need to perform certain actions with the cell’s in-place editor. This topic describes how you can activate the editor and apply the changes made:

To perform these actions, TestComplete should have access to internal objects, properties and methods of the GridControl object. For this purpose, the .NET Application Support plugin must be installed and enabled.

When testing Syncfusion GridControl 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 GridControl 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.

Activating In-place Editors

It is possible to activate the focused cell’s in-place editor in the following ways:

  • By clicking the focused cell (if the grid’s ActivateCurrentCellBehavior property is “DblClickOnCell”, double click is required).
  • By pressing the F2 key.
  • By typing into the focused cell. At that, the cell’s value is replaced by the value typed.
  • Using the grid’s CurrentCell.BeginEdit method.

The following ActivateInplaceEditor routine demonstrates how to implement some of the described approaches. Its Grid parameter specifies the tested GridControl. If you decide to activate the edit mode by clicking the cell, remember to include the helper ClickCell routine from the Selecting Cells in Syncfusion GridControl topic in your test script.

JavaScript, JScript

function ActivateCellEditor (Grid)
{
  if (!Grid.CurrentCell.IsEditing)
  {
    // Use any of the following statements --

    // Simulate the F2 shortcut
    Grid.Keys ("[F2]")

    // Click the cell
    // ClickCell (Grid, Grid.CurrentCell.RowIndex, Grid.CurrentCell.ColIndex);

    // Call the CurrentCell.BeginEdit method:
    // Grid.CurrentCell.BeginEdit();
  }
}

Python

def ActivateCellEditor (Grid):
  if not Grid.CurrentCell.IsEditing:
    # Use any of the following statements --

    # Simulate the F2 shortcut
    Grid.Keys ("[F2]")

    # Click the cell
    # ClickCell (Grid, Grid.CurrentCell.RowIndex, Grid.CurrentCell.ColIndex)

    # Call the CurrentCell.BeginEdit method:
    # Grid.CurrentCell.BeginEdit()

VBScript

Sub ActivateCellEditor (Grid)
  If Not Grid.CurrentCell.IsEditing Then
    ' Use any of the following statements --

    ' Simulate the F2 shortcut
    Call Grid.Keys ("[F2]")

    ' Click the cell
    ' Call ClickCell (Grid, Grid.CurrentCell.RowIndex, Grid.CurrentCell.ColIndex)

    ' Call the CurrentCell.BeginEdit method:
    ' Grid.CurrentCell.BeginEdit
  End If
End Sub

DelphiScript

procedure ActivateCellEditor (Grid);
begin
  if not Grid.CurrentCell.IsEditing then
  begin
    // Use any of the following statements --

    // Simulate the F2 shortcut
    Grid.Keys ('[F2]')

    // Click the cell
    // ClickCell (Grid, Grid.CurrentCell.RowIndex, Grid.CurrentCell.ColIndex);

    // Call the CurrentCell.BeginEdit method:
    // Grid.CurrentCell.BeginEdit;
  end
end;

C++Script, C#Script

function ActivateCellEditor (Grid)
{
  if (!Grid["CurrentCell"]["IsEditing"])
  {
    // Use any of the following statements --

    // Simulate the F2 shortcut
    Grid["Keys"]("[F2]")

    // Click the cell
    // ClickCell (Grid, Grid["CurrentCell"]["RowIndex"], Grid["CurrentCell"]["ColIndex"]);

    // Call the CurrentCell.BeginEdit method:
    // Grid["CurrentCell"]["BeginEdit"]();
  }
}

Closing In-place Editors

After you have inputted the new cell value, you need to close the editor and save the changes made. You can do this in two ways:

  • By simulating the Enter key press.
  • By using the grid’s CurrentCell.EndEdit method.

The code snippet below contains the CloseCellEditor routine that can be used to finish editing the grid cell value. The Grid parameter of this routine specifies the GridControl under which the action is performed.

JavaScript, JScript

function CloseCellEditor (Grid)
{
  // Use any of the following statements --

  // Simulate the Enter keypress
  Grid.Keys ("[Enter]");

  // Call the CurrentCell.EndEdit method:
  // Grid.CurrentCell.EndEdit();
}

Python

def CloseCellEditor (Grid):
  # Use any of the following statements --

  # Simulate the Enter keypress
  Grid.Keys ("[Enter]")

  # Call the CurrentCell.EndEdit method:
  # Grid.CurrentCell.EndEdit()

VBScript

Sub CloseCellEditor (Grid)
  ' Use any of the following statements --

  ' Simulate the Enter keypress
  Call Grid.Keys ("[Enter]")

  ' Call the CurrentCell.EndEdit method:
  ' Grid.CurrentCell.EndEdit
End Sub

DelphiScript

procedure CloseCellEditor (Grid);
begin
  // Use any of the following statements --

  // Simulate the Enter keypress
  Grid.Keys ('[Enter]');

  // Call the CurrentCell.EndEdit method:
  // Grid.CurrentCell.EndEdit;
end;

C++Script, C#Script

function CloseCellEditor (Grid)
{
  // Use any of the following statements --

  // Simulate the Enter keypress
  Grid["Keys"]("[Enter]");

  // Call the CurrentCell.EndEdit method:
  // Grid["CurrentCell"]["EndEdit"]();
}

You may also need to cancel the editing and discard any changes made to the cell value. For this purpose, you can either send the Esc key press to the grid control, or use the grid’s CurrentCell.CancelEdit method. The CancelEdit routine in the example below demonstrates how to do this:

JavaScript, JScript

function CancelEdit (Grid)
{
  // Use any of the following statements --

  // Simulate the Esc keypress
  Grid.Keys ("[Esc]");

  // Call the CurrentCell.CancelEdit method:
  // Grid.CurrentCell.CancelEdit();
}

Python

def CancelEdit (Grid):
  # Use any of the following statements --

  # Simulate the Esc keypress
  Grid.Keys ("[Esc]")

  # Call the CurrentCell.CancelEdit method:
  # Grid.CurrentCell.CancelEdit()

VBScript

Sub CancelEdit (Grid)
  ' Use any of the following statements --

  ' Simulate the Esc keypress
  Call Grid.Keys ("[Esc]")

  ' Call the CurrentCell.CancelEdit method:
  ' Grid.CurrentCell.CancelEdit
End Sub

DelphiScript

procedure CancelEdit (Grid);
begin
  // Use any of the following statements --

  // Simulate the Esc keypress
  Grid.Keys ('[Esc]');

  // Call the CurrentCell.CancelEdit method:
  // Grid.CurrentCell.CancelEdit;
end;

C++Script, C#Script

function CancelEdit (Grid)
{
  // Use any of the following statements --

  // Simulate the Esc keypress
  Grid["Keys"]("[Esc]");

  // Call the CurrentCell.CancelEdit method:
  // Grid["CurrentCell"]["CancelEdit"]();
}

See Also

Working With Syncfusion GridControl
Accessing Rows, Columns and Cells in Syncfusion GridControl
Selecting Cells in Syncfusion GridControl
Obtaining and Setting Cell Values in Syncfusion GridControl

Highlight search results