Activating In-place Editors in Developer Express QuantumGrid

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

The QuantumGrid control lets users change data directly within grid cells. This topic explains how you can activate an in-place editor from scripts.

In order for TestComplete to be able to perform these actions, the following conditions must be met: Note also, that the compiler can exclude methods and properties that are not called in the application’s source code from the application’s binary code, so these methods and properties are unavailable to TestComplete (see Object Properties, Fields and Methods That Are Unavailable to TestComplete). To solve the problem, make sure that the desired methods and properties are used in the application’s source code. For instance, you can add a virtual method to your application that calls the desired methods and properties (the compiler does not exclude virtual methods).

When testing Developer Express QuantumGrid controls, use specific methods and properties of the corresponding DevExpressQuantumGrid 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 QuantumGrid 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.

Genaral Notes

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 Developer Express QuantumGrid. The Selecting Cells in Developer Express QuantumGrid topic explains how you can select the desired grid cell.

Activating In-place Editors With Keyboard Shortcuts

The focused cell’s in-place editor can be activated upon pressing the F2 key. You can simulate this key press using the Keys action applied to the TcxGrid object. The following code demonstrates how you can do this:

Example

View description

JavaScript

function Main()
{
var p, Grid, View;
var ParentRowIndex, ParentView, RowIndex, ColumnId, ChildViewId;
  
  ParentRowIndex=2;
  ParentView=0;
  RowIndex=4;
  ColumnId=2;
  ChildViewId=1;
  
  // Obtain the application process
  p = Sys.Process("MySampleApp");
  // Obtain the grid object
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  // Obtain child view
  View = Grid.wChildLevel(ParentRowIndex, ParentView);
  
  // Activate in-place editor
  ActivateCellInplaceEditor(Grid, View, RowIndex, ColumnId, ChildViewId);
}

// Activate in-place editor
function ActivateCellInplaceEditor(grid, view, rowIndex, columnId, childViewId)
{
  if (strictEqual(view, null))
      ActiveView = grid;
    else
      ActiveView = view;

  // Select the cell
  ActiveView.ClickCell(rowIndex, columnId, childViewId);
  // Simulate keystroke
  grid.Keys("[F2]");
}

JScript

function Main()
{
var p, Grid, View;
var ParentRowIndex, ParentView, RowIndex, ColumnId, ChildViewId;
  
  ParentRowIndex=2;
  ParentView=0;
  RowIndex=4;
  ColumnId=2;
  ChildViewId=1;
  
  // Obtain the application process
  p = Sys.Process("MySampleApp");
  // Obtain the grid object
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  // Obtain child view
  View = Grid.wChildLevel(ParentRowIndex, ParentView);
  
  // Activate in-place editor
  ActivateCellInplaceEditor(Grid, View, RowIndex, ColumnId, ChildViewId);
}

// Activate in-place editor
function ActivateCellInplaceEditor(grid, view, rowIndex, columnId, childViewId)
{
  if (view == null)
      ActiveView = grid;
    else
      ActiveView = view;

  // Select the cell
  ActiveView.ClickCell(rowIndex, columnId, childViewId);
  // Simulate keystroke
  grid.Keys("[F2]");
}

Python

def Main():
  
  ParentRowIndex=2
  ParentView=0
  RowIndex=4
  ColumnId=2
  ChildViewId=1
  
  # Obtain the application process 
  p = Sys.Process("MySampleApp")
  # Obtain the grid object 
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  # Obtain child view
  View = Grid.wChildLevel(ParentRowIndex, ParentView)
  
  # Activate in-place editor
  ActivateCellInplaceEditor(Grid, View, RowIndex, ColumnId, ChildViewId)

# Activate in-place editor
def ActivateCellInplaceEditor(grid, view, rowIndex, columnId, childViewId):
  if (view == None):
    ActiveView = grid
  else:
    ActiveView = view

  # Select the cell
  ActiveView.ClickCell(rowIndex, columnId, childViewId)
  # Simulate keystroke
  grid.Keys("[F2]")

VBScript

Sub Main
  ParentRowIndex=2
  ParentView=0
  RowIndex=4
  ColumnId=2
  ChildViewId=1
  
  ' Obtain the application process
  Set p = Sys.Process("MySampleApp")
  ' Obtain the grid object
  Set Grid = p.VCLObject("FormName").VCLObject("GridName")
  ' Obtain child view
  Set View = Grid.wChildLevel(ParentRowIndex, ParentView)
  
  ' Activate in-place editor
  Call ActivateCellInplaceEditor(Grid, View, RowIndex, ColumnId, ChildViewId)
End Sub

' Activate in-place editor
Sub ActivateCellInplaceEditor(grid, view, rowIndex, columnId, childViewId)

  If view Is Nothing Then 
      Set ActiveView = grid
    Else
      Set ActiveView = view
  End If

  ' Select the cell
  Call ActiveView.ClickCell(rowIndex, columnId, childViewId)
  ' Simulate keystroke
  Call grid.Keys("[F2]")
End Sub

DelphiScript

procedure ActivateCellInplaceEditor(grid, view: OleVariant; rowIndex: integer; columnId, childViewId: OleVariant);forward;

procedure Main;
var p, Grid, View:OleVariant;
    ParentRowIndex, ParentView, RowIndex, ColumnId, ChildViewId: integer;
begin
  ParentRowIndex:=2;
  ParentView:=0;
  RowIndex:=4;
  ColumnId:=2;
  ChildViewId:=1;
  
  // Obtain the application process
  p := Sys.Process('MySampleApp');
  // Obtain the grid object
  Grid := p.VCLObject('FormName').VCLObject('GridName');
  // Obtain child view
  View := Grid.wChildLevel(ParentRowIndex, ParentView);
  
  // Activate in-place editor
  ActivateCellInplaceEditor(Grid, View, RowIndex, ColumnId, ChildViewId);
end;

// Activate in-place editor
procedure ActivateCellInplaceEditor(grid, view: OleVariant; rowIndex: integer; columnId, childViewId: OleVariant);
var ActiveView: OleVariant;
begin

  if view = nil then 
      ActiveView := grid
    else
      ActiveView := view;

  // Select the cell
  ActiveView.ClickCell(rowIndex, columnId, childViewId);
  // Simulate keystroke
  grid.Keys('[F2]');
end;

C++Script, C#Script

function Main()
{
var p, Grid, View;
var ParentRowIndex, ParentView, RowIndex, ColumnId, ChildViewId;
  
  ParentRowIndex=2;
  ParentView=0;
  RowIndex=4;
  ColumnId=2;
  ChildViewId=1;
  
  // Obtain the application process
  p = Sys["Process"]("MySampleApp");
  // Obtain the grid object
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");
  // Obtain child view
  View = Grid["wChildLevel"](ParentRowIndex, ParentView);
  
  // Activate in-place editor
  ActivateCellInplaceEditor(Grid, View, RowIndex, ColumnId, ChildViewId);
}

// Activate in-place editor
function ActivateCellInplaceEditor(grid, view, rowIndex, columnId, childViewId)
{
  if (view == null)
      ActiveView = grid;
    else
      ActiveView = view;

  // Select the cell
  ActiveView["ClickCell"](rowIndex, columnId, childViewId);
  // Simulate keystroke
  grid["Keys"]("[F2]");
}

Activating In-place Editors Using TcxGrid Internal Methods

You can also activate an in-place editor by calling the Controller.EditingController.ShowEdit method of the view object that is used by the TcxGrid object (TcxGrid is the class name of QuantumGrid controls). The ShowEdit method can use one or several parameters that specify various options. For more information on these parameters, please see the QuantumGrid documentation. In our example, we will only pass one parameter to this method - null (JavaScript, JScript, C#Script, C++Script), None (Python), 0 (VBScript) or nil (DelphiScript). The following code demonstrates how to activate an in-place editor by calling the ShowEdit method.

Example

View description

JavaScript

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

  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  // Set Grid = GetGrid1
  
  // Activate in-place editor
  ActivateCellInplaceEditor(Grid, null, 4, 3);
}

// Activate in-place editor
function ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
{
  // Select the view object
  if (strictEqual(view, null))
    view = grid.ActiveView;
  // Select the cell
  SelectGridCell(grid, view, rowIndex, columnId);
  // Activate in-place editor
  view.Controller.EditingController.ShowEdit(null);
}

// Select grid cell
function SelectGridCell(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (isNull(view))
    view = grid.ActiveView;
  // Select the column
  view.Controller.FocusedColumn = GetColumn(grid, view, columnId);
  // Select the row
  view.Controller.FocusedRowIndex = rowIndex;
}

// Obtain column object
function GetColumn(grid, view, columnId)
{
  
  // Get the view
  if (isNull(view))
    view = grid.ActiveView;
  
  // Check type of the columnId parameter
  if (equal(aqObject.GetVarType(columnId), varOleStr))
  {
    // If columnId is a string,
    // then search for column by its caption
    for (let i = 0; i < view.ColumnCount; i++)
      if (equal(view.Columns(i).Caption, columnId))
        return view.Columns(i);
  }
  else
  {
    // If columnId is an integer,
    // then search for column by its index
    for (let i = 0; i < view.ColumnCount; i++)
      if (equal(view.Columns(i).VisibleIndex, columnId))
        return view.Columns(i);
  }
}

JScript

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

  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  // Set Grid = GetGrid1
  
  // Activate in-place editor
  ActivateCellInplaceEditor(Grid, null, 4, 3);
}

// Activate in-place editor
function ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
{
  // Select the view object
  if (view == null)
    view = grid.ActiveView;
  // Select the cell
  SelectGridCell(grid, view, rowIndex, columnId);
  // Activate in-place editor
  view.Controller.EditingController.ShowEdit(null);
}

// Select grid cell
function SelectGridCell(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (view == null)
    view = grid.ActiveView;
  // Select the column
  view.Controller.FocusedColumn = GetColumn(grid, view, columnId);
  // Select the row
  view.Controller.FocusedRowIndex = rowIndex;
}

// Obtain column object
function GetColumn(grid, view, columnId)
{
  var i;
  
  // Get the view
  if (view == null)
    view = grid.ActiveView;
  
  // Check type of the columnId parameter
  if (aqObject.GetVarType(columnId) == varOleStr)
  {
    // If columnId is a string,
    // then search for column by its caption
    for (i = 0; i < view.ColumnCount; i++)
      if (view.Columns(i).Caption == columnId)
        return view.Columns(i);
  }
  else
  {
    // If columnId is an integer,
    // then search for column by its index
    for (i = 0; i < view.ColumnCount; i++)
      if (view.Columns(i).VisibleIndex == columnId)
        return view.Columns(i);
  }
}

Python

def Main():

  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  # Set Grid = GetGrid1
  
  # Activate in-place editor
  ActivateCellInplaceEditor(Grid, None, 4, 3)

# Activate in-place editor
def ActivateCellInplaceEditor2(grid, view, rowIndex, columnId):
  # Select the view object
  if (view == None):
    view = grid.ActiveView
  # Select the cell
  SelectGridCell(grid, view, rowIndex, columnId)
  # Activate in-place editor 
  view.Controller.EditingController.ShowEdit(None)

# Select grid cell 
def SelectGridCell(grid, view, rowIndex, columnId):
  # Obtain the view object 
  if (view == None):
    view = grid.ActiveView
  # Select the column 
  view.Controller.FocusedColumn = GetColumn(grid, view, columnId)
  # Select the row 
  view.Controller.FocusedRowIndex = rowIndex

# Obtain column object
def GetColumn(grid, view, columnId):
  
  # Get the view
  if (view == None):
    view = grid.ActiveView 
  
  # Check type of the columnId parameter 
  if (aqObject.GetVarType(columnId) == varOleStr):
    # If columnId is a string,
    # then search for column by its caption
    for i in range(0, view.ColumnCount-1):
      if (view.Columns[i].Caption == columnId):
        return view.Columns[i]
  else:
    # If columnId is an integer,
    # then search for column by its index
    for i in range(0, view.ColumnCount-1):
      if (view.Columns[i].VisibleIndex == columnId):
        return view.Columns[i]

VBScript

Sub Main
  Set p = Sys.Process("MySampleApp")
  Set Grid = p.VCLObject("FormName").VCLObject("GridName")
  'Set Grid = GetGrid1
  
  ' Activate in-place editor
  Call ActivateCellInplaceEditor(Grid, Nothing, 4, 3)
End Sub

' Activate in-place editor
Sub ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If
  ' Select the cell
  Call SelectGridCell(grid, view, rowIndex, columnId)
  ' Activate in-place editor
  Call view.Controller.EditingController.ShowEdit(0)
End Sub

' Select grid cell
Sub SelectGridCell(grid, view, rowIndex, columnId)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If
  ' Select the column
  view.Controller.FocusedColumn = GetColumn(grid, view, columnId)
  ' Select the row
  view.Controller.FocusedRowIndex = rowIndex
End Sub

' Obtain column object
Function GetColumn(grid, view, columnId)
  Dim Columns, i
  
  ' Get the view
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If
            
  ' Check type of the columnId parameter
  If aqObject.GetVarType(columnId) = varOleStr Then
    ' If columnId is a string,
    ' then search for column by its caption
    For i = 0 to view.ColumnCount - 1
      If view.Columns(i).Caption = columnId Then
        Set GetColumn = view.Columns(i)
        Exit For
      End If
    Next 
  Else
    ' If columnId is an integer,
    ' then search for column by its index
    For i = 0 to view.ColumnCount - 1
      If view.Columns(i).VisibleIndex = columnId Then
        Set GetColumn = view.Columns(i)
        Exit For
      End If
    Next
  End If
End Function

DelphiScript

procedure SelectGridCell(grid, view, rowIndex, columnId); forward;
procedure ActivateCellInplaceEditor(grid, view, rowIndex, columnId); forward;
function GetColumn(grid, view, columnId): Variant; forward;

procedure Main;
var
  p, Grid : OleVariant;
begin
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');
  
  // Activate in-place editor
  ActivateCellInplaceEditor(Grid, nil, 4, 3);
end;

// Activate in-place editor
procedure ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;
  // Select the cell
  SelectGridCell(grid, view, rowIndex, columnId);
  // Activate in-place editor
  view.Controller.EditingController.ShowEdit(nil);
end;

// Select grid cell
procedure SelectGridCell(grid, view, rowIndex, columnId);
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;
  // Select the column
  view.Controller.FocusedColumn := GetColumn(grid, view, columnId);
  // Select the row
  view.Controller.FocusedRowIndex := rowIndex;
end;

// Obtain column object
function GetColumn(grid, view, columnId): Variant;
var
  i: Variant;
begin
  // Get the view
  if view = nil then
    view := grid.ActiveView;
    
  // Check type of the columnId parameter
  if aqObject.GetVarType(columnId) = varOleStr then
  begin
    // If columnId is a string,
    // then search for column by its caption
    for i := 0 to view.ColumnCount - 1 do
      if view.Columns[i].Caption = columnId then
        Result := view.Columns[i];
  end 
  else
    // If columnId is an integer,
    // then search for column by its index
    for i := 0 to view.ColumnCount - 1 do
      if view.Columns[i].VisibleIndex = columnId then
        Result := view.Columns[i];
end;

C++Script, C#Script

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

  p = Sys["Process"]("MySampleApp");
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");
  
  // Activate in-place editor
  ActivateCellInplaceEditor(Grid, null, 4, 3);
}

// Activate in-place editor
function ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (view == null)
    view = grid.ActiveView;
  // Select the cell
  SelectGridCell(grid, view, rowIndex, columnId);
  // Activate the in-place editor
  view.Controller.EditingController.ShowEdit(null);
}

// Select grid cell
function SelectGridCell(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (view == null)
    view = grid["ActiveView"];
  // Select the column
  view["Controller"]["FocusedColumn"] = GetColumn(grid, view, columnId);
  // Select the row
  view["Controller"]["FocusedRowIndex"] = rowIndex;
}

// Obtain column object
function GetColumn(grid, view, columnId)
{
  var i;
  
  // Get the view
  if (view == null)
    view = grid["ActiveView"];
  
  // Check type of the columnId parameter
  if (aqObject["GetVarType"](columnId) == varOleStr)
  {
    // If columnId is a string,
    // then search for column by its caption
    for (i = 0; i < view["ColumnCount"]; i++)
      if (view["Columns"](i)["Caption"] == columnId)
        return view["Columns"](i);
  }
  else
  {
    // If columnId is an integer,
    // then search for column by its index
    for (i = 0; i < view["ColumnCount"]; i++)
      if (view["Columns"](i)["VisibleIndex"] == columnId)
        return view["Columns"](i);
  }
}

Closing In-place Editors

To finish editing the QuantumGrid cell value and save any changes made, the user should press the Enter key, or select another grid cell. You can simulate the Enter keypress using the Keys action.

The following code snippet contains the CloseCellEditor routine that can be used to save changes made to a grid cell. The Grid parameter of this routine specifies the grid control under which the action is performed:

JavaScript, JScript

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

Python

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

VBScript

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

DelphiScript

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

C++Script, C#Script

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

You may also need to cancel the editing and discard any changes made to the cell. This happens when the user presses Esc. To simulate the Esc key press, use the Keys action. The CancelEditing routine in the code snippet below demonstrates how to do this:

JavaScript, JScript

function CancelEditing (grid)
{
  grid.Keys ("[Esc]");
}

Python

def CancelEditing (grid):
  grid.Keys ("[Esc]")

VBScript

Sub CancelEditing (grid)
  grid.Keys "[Esc]"
End Sub

DelphiScript

procedure CancelEditing (grid);
begin
  grid.Keys ('[Esc]');
end;

C++Script, C#Script

function CancelEditing (grid)
{
  grid["Keys"] ("[Esc]");
}

See Also

Working With Developer Express QuantumGrid
Selecting Cells in Developer Express QuantumGrid
Working With Specific In-place Editors in Developer Express QuantumGrid

Highlight search results