Activating In-place Editors in Borland TDBGrid

Applies to TestComplete 15.47, last modified on January 20, 2023

The TDBGrid control lets users change data directly within grid cells. This topic explains how you can activate an in-place editor from scripts. Note that before activating the cell’s in-place editor, you need to locate the desired cell within the grid and select it. To search for the desired row, you can use the methods described here: Searching for Records in Borland TDBGrid. The Selecting Cells in Borland TDBGrid topic explains how you can select the desired grid cell.

To perform these actions, TestComplete must have access to internal methods and properties of the TDBGrid control. This requires the following conditions be met:

When testing Borland TDBGrid controls, use specific methods and properties of the corresponding BorlandTDBGrid 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 TDBGrid 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.

It is possible to activate the edit mode of the current cell in the following ways:

  • By clicking the cell. You can use the ClickCell action of a BorlandTDBGrid object corresponding to the TDBGrid control.
  • By pressing the Enter or F2 key. You can simulate this key press using the Keys action applied to the grid control.
  • By setting the grid’s EditorMode property to True.

The following example demonstrates how you can implement some of these approaches in scripts:

Example

View description

JavaScript, JScript

function Main ()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys.Process("csdemos");
  p.VCLObject("FrmLauncher").VCLObject("BtnViews").ClickButton();
  Grid = p.VCLObject("FrmViewDemo").VCLObject("Panel2").VCLObject("DBGrid1");

  ActivateCellEditor (Grid, 2, "LastName");
  Grid.Keys ("Clemens" + "[Enter]");
}

function ActivateCellEditor (Grid, RowIndex, ColumnId)
{
  // Select the cell
  Grid.ClickCell (RowIndex, ColumnId);

  // Use any of the following statements to activate the edit mode:
  // Grid.ClickCell (RowIndex, ColumnId);   // Click the cell
  Grid.Keys ("[Enter]");   // Simulate the Enter shortcut
}

Python

def Main():

  # Obtain the grid object
  p = Sys.Process("csdemos")
  p.VCLObject("FrmLauncher").VCLObject("BtnViews").ClickButton()
  Grid = p.VCLObject("FrmViewDemo").VCLObject("Panel2").VCLObject("DBGrid1")

  ActivateCellEditor (Grid, 2, "LastName")
  Grid.Keys ("Clemens" + "[Enter]")

def ActivateCellEditor (Grid, RowIndex, ColumnId):
  # Select the cell
  Grid.ClickCell (RowIndex, ColumnId)

  # Use any of the following statements to activate the edit mode:
  # Grid.ClickCell (RowIndex, ColumnId)   # Click the cell
  Grid.Keys ("[Enter]")   # Simulate the Enter shortcut

VBScript

Sub Main
  Dim p, Grid

  ' Obtain the grid object
  Set p = Sys.Process("csdemos")
  p.VCLObject("FrmLauncher").VCLObject("BtnViews").ClickButton
  Set Grid = p.VCLObject("FrmViewDemo").VCLObject("Panel2").VCLObject("DBGrid1")

  Call ActivateCellEditor (Grid, 2, "LastName")
  Grid.Keys ("Clemens" & "[Enter]")
End Sub

Sub ActivateCellEditor (Grid, RowIndex, ColumnId)
  ' Select the cell
  Call Grid.ClickCell (RowIndex, ColumnId)

  ' Use any of the following statements to activate the edit mode:
  ' Call Grid.ClickCell (RowIndex, ColumnId)   ' Click the cell
  Grid.Keys ("[Enter]")   ' Simulate the Enter shortcut
End Sub

DelphiScript

procedure ActivateCellEditor (Grid, RowIndex, ColumnId);
begin
  // Select the cell
  Grid.ClickCell (RowIndex, ColumnId);

  // Use any of the following statements to activate the edit mode:
  // Grid.ClickCell (RowIndex, ColumnId);   // Click the cell
  Grid.Keys ('[Enter]');   // Simulate the Enter shortcut
end;

procedure Main;
var p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('csdemos');
  p.VCLObject('FrmLauncher').VCLObject('BtnViews').ClickButton;
  Grid := p.VCLObject('FrmViewDemo').VCLObject('Panel2').VCLObject('DBGrid1');

  ActivateCellEditor (Grid, 2, 'LastName');
  Grid.Keys ('Clemens' + '[Enter]');
end;

C++Script, C#Script

function Main ()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys["Process"]("csdemos");
  p["VCLObject"]("FrmLauncher")["VCLObject"]("BtnViews")["ClickButton"]();
  Grid = p["VCLObject"]("FrmViewDemo")["VCLObject"]("Panel2")["VCLObject"]("DBGrid1");

  ActivateCellEditor (Grid, 2, "LastName");
  Grid["Keys"]("Clemens" + "[Enter]");
}

function ActivateCellEditor (Grid, RowIndex, ColumnId)
{
  // Select the cell
  Grid["ClickCell"](RowIndex, ColumnId);

  // Use any of the following statements to activate the edit mode:
  // Grid["ClickCell"](RowIndex, ColumnId);   // Click the cell
  Grid["Keys"]("[Enter]");   // Simulate the Enter shortcut
}

See Also

Working With Borland TDBGrid
Selecting Cells in Borland TDBGrid
Obtaining and Setting Cell Values in Borland TDBGrid
ClickCell Action (Grid Controls)
Keys Action

Highlight search results