Working With Specific In-place Editors in Developer Express QuantumGrid

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

The Developer Express QuantumGrid control offers a lot of various column types. Each column type provides a specific in-place editor for modifying cell values. This topic describes how you can change values in cells that use specific in-place editors such as check boxes, radio buttons, spin boxes and drop-down lists.

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.

Accessing In-place Editors

In QuantumGrid, the cell editing operations are managed by special editing controller objects. To access these objects, use the Controller.EditingController property of the desired view object (for more information on views, see Getting Views in Developer Express QuantumGrid and QuantumGrid documentation).

When a user starts editing the cell value, the grid creates an edit control (in-place editor) for this. This edit control’s type corresponds to the column type. For instance, if a column uses a combo box, the grid will create the combo box editor. To access the editor, use the Edit property of the editing controller object. If there is no in-place editor, the property returns an empty value. To check if the grid is in the editing mode, you can use the IsEditing property of the editing control.

After you obtain the scripting access to the edit control, you can use methods and properties of this control to perform the desired actions. For example, the DropDown method of the combo box editor will display the drop-down list and the Text property of the edit box editor will return the currently specified text. The following sections of this topic demonstrate typical operations for some of the controls.

Working With Check Box Editors

To change data in a cell that uses a check box editor, you can create a script that will perform the following actions:

  • Select the cell and activate the editor.
  • Simulate the Space keystroke over the cell (this keystroke selects or unselects the check box).
Example

View description

JavaScript

function Main()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  // Change check box values
  SetCheckBoxEditor(Grid, null, 2, "CheckBoxColumn", true);
  SetCheckBoxEditor(Grid, null, 4, "CheckBoxColumn", false);
}

// Change value of the check box editor
function SetCheckBoxEditor(grid, view, rowIndex, columnId, value)
{
  let editor;
  
  // Obtain the view object
  if (strictEqual(view, null))
    view = grid.ActiveView;

  // Activate the editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);

  // If the editor is a check box editor, ...
  if(equal(view.Controller.EditingController.Edit.ClassName, "TcxCheckBox"))
  {
    // ... obtain the edit control
    editor = view.Controller.EditingController.Edit;
    // Assign the value
    if(editor.Checked != value)
      grid.Keys(" ");
  }
}

JScript

function Main()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  // Change check box values
  SetCheckBoxEditor(Grid, null, 2, "CheckBoxColumn", true);
  SetCheckBoxEditor(Grid, null, 4, "CheckBoxColumn", false);
}

// Change value of the check box editor
function SetCheckBoxEditor(grid, view, rowIndex, columnId, value)
{
  var editor;
  
  // Obtain the view object
  if (view == null)
    view = grid.ActiveView;

  // Activate the editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);

  // If the editor is a check box editor, ...
  if(view.Controller.EditingController.Edit.ClassName == "TcxCheckBox")
  {
    // ... obtain the edit control
    editor = view.Controller.EditingController.Edit;
    // Assign the value
    if(editor.Checked != value)
      grid.Keys(" ");
  }
}

Python

def Main():

  # Obtain the grid object
  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  
  # Change check box values
  SetCheckBoxEditor(Grid, None, 2, "CheckBoxColumn", True)
  SetCheckBoxEditor(Grid, None, 4, "CheckBoxColumn", False)

# Change value of the check box editor
def SetCheckBoxEditor(grid, view, rowIndex, columnId, value):
  
  # Obtain the view object
  if (view == None):
    view = grid.ActiveView

  # Activate the editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId)

  # If the editor is a check box editor, ...
  if(view.Controller.EditingController.Edit.ClassName == "TcxCheckBox"):
    # ... obtain the edit control
    editor = view.Controller.EditingController.Edit
    # Assign the value
    if(editor.Checked != value):
      grid.Keys(" ")

VBScript

Sub Main
  ' Obtain the grid object
  Set p = Sys.Process("MySampleApp")
  Set Grid = p.VCLObject("FormName").VCLObject("GridName")

  ' Change check box values
  Call SetCheckBoxEditor(Grid, Nothing, 2, "CheckBoxColumn", True)
  Call SetCheckBoxEditor(Grid, Nothing, 4, "CheckBoxColumn", False)
End Sub

' Change value of the check box editor
Sub SetCheckBoxEditor(grid, view, rowIndex, columnId, value)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If

  ' Activate the editor
  Call ActivateCellInplaceEditor(grid, view, rowIndex, columnId)

  ' If the editor is a check box editor, ...
  If view.Controller.EditingController.Edit.ClassName = "TcxCheckBox" Then
    ' ... obtain the edit control
    Set editor = view.Controller.EditingController.Edit
    ' Assign the value
    If editor.Checked <> value Then
      Call grid.Keys(" ")
    End If
  End If
End Sub 

DelphiScript

procedure SetCheckBoxEditor(grid, view, rowIndex, columnId, value); forward;
procedure ActivateCellInplaceEditor(grid, view, rowIndex, columnId); forward;

procedure Main;
var
  p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');
      
  // Change check box values
  SetCheckBoxEditor(Grid, nil, 2, 'CheckBoxColumn', True);
  SetCheckBoxEditor(Grid, nil, 3, 'CheckBoxColumn', False);
end;

// Change value of the check box editor
procedure SetCheckBoxEditor(grid, view, rowIndex, columnId, value);
var
  editor : OleVariant;
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;

  // Activate the editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);

  // If the editor is a check box editor, ...
  if view.Controller.EditingController.Edit.ClassName = 'TcxCheckBox' then
  begin
    // ... obtain the edit control
    editor := view.Controller.EditingController.Edit;
    // Assign the value
    if editor.Checked <> value then
      grid.Keys(' ');
  end;
end;

C++Script, C#Script

function Main()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys["Process"]("MySampleApp");
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");
  
  // Change check box values
  SetCheckBoxEditor(Grid, null, 2, "CheckBoxColumn", true);
  SetCheckBoxEditor(Grid, null, 3, "CheckBoxColumn", false);
}

// Change value of the check box editor
function SetCheckBoxEditor(grid, view, rowIndex, columnId, value)
{
  var editor;
  
  // Obtain the view object
  if (view == null)
    view = grid["ActiveView"];

  // Activate the editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);

  // If the editor is a check box editor, ...
  if(view["Controller"]["EditingController"]["Edit"]["ClassName"] == "TcxCheckBox")
  {
    // ... obtain the edit control
    editor = view["Controller"]["EditingController"]["Edit"];
    // Assign the value
    if(editor["Checked"] != value)
      grid["Keys"](" ");
  }
}

Working With Radio Button Editors

An in-place editor may contain radio buttons. The object that corresponds to the radio button's in-place editor contain the Buttons(index) property that provides a scripting interface to the radio buttons (the index parameter is the zero-based index of the desired button). The button’s Selected property specifies whether the button is currently selected or not.

Before assigning True to the Selected property, call the SetFocus method of the button object. This will move focus to the button. It is important to move the focus to the button. Else, the button selection will not be saved.

To confirm the selection, simulate the Enter keystroke.

Changing the value of a radio button editor includes the following steps:

  1. Obtaining the editor object.
  2. Obtaining the button object.
  3. Calling the SetFocus method of the button object.
  4. Assigning True to the Selected property of the button object.
  5. Simulating the Enter keystroke for the editor.
Example

View description

JavaScript

function Main()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  // Select radio buttons
  SetRadioButtonEditor(Grid, null, 4, "RadioGroupColumn", 1);
}

// Working with the radio button editor
function SetRadioButtonEditor(grid, view, rowIndex, columnId, RadioButtonIndex)
{
  var editor, btn;

  // Obtain the view object
  if(strictEqual(view, null))
    view = grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
    
  // Obtain the editor
  editor = view.Controller.EditingController.Edit;
  // Checks the editor's class name
  if(equal(editor.ClassName, "TcxRadioGroup"))
  {
    // Obtain the button
    btn = editor.Buttons(RadioButtonIndex);
    // Set the value
    btn.SetFocus();
    btn.Checked = true;
    // Confirm the change
    grid.Keys("[Enter]");
  }
}

JScript

function Main()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  // Select radio buttons
  SetRadioButtonEditor(Grid, null, 4, "RadioGroupColumn", 1);
}

// Working with the radio button editor
function SetRadioButtonEditor(grid, view, rowIndex, columnId, RadioButtonIndex)
{
  var editor, btn;

  // Obtain the view object
  if(view == null)
    view = grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
    
  // Obtain the editor
  editor = view.Controller.EditingController.Edit;
  // Checks the editor's class name
  if(editor.ClassName == "TcxRadioGroup")
  {
    // Obtain the button
    btn = editor.Buttons(RadioButtonIndex);
    // Set the value
    btn.SetFocus();
    btn.Checked = true;
    // Confirm the change
    grid.Keys("[Enter]");
  }
}

Python

def Main():

  # Obtain the grid object
  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  
  # Select radio buttons
  SetRadioButtonEditor(Grid, None, 4, "RadioGroupColumn", 1)

# Working with the radio button editor
def SetRadioButtonEditor(grid, view, rowIndex, columnId, RadioButtonIndex):

  # Obtain the view object 
  if(view == None):
    view = grid.ActiveView

  # Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
    
  # Obtain the editor
  editor = view.Controller.EditingController.Edit
  # Checks the editor's class name
  if(editor.ClassName == "TcxRadioGroup"):
    # Obtain the button
    btn = editor.Buttons(RadioButtonIndex)
    # Set the value
    btn.SetFocus()
    btn.Checked = True
    # Confirm the change
    grid.Keys("[Enter]")

VBScript

Sub Main
  ' Obtain the grid object
  Set p = Sys.Process("MySampleApp")
  Set Grid = p.VCLObject("FormName").VCLObject("GridName")

  ' Select radio buttons
  Call SetRadioButtonEditor(Grid, Nothing, 4, "RadioGroupColumn", 1)
End Sub

' Working with the radio button editor
Sub SetRadioButtonEditor(grid, view, rowIndex, columnId, RadioButtonIndex)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If

  ' Activate the in-place editor
  Call ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
    
  ' Obtain the editor
  Set editor = view.Controller.EditingController.Edit
  ' Checks the editor's class name
  If editor.ClassName = "TcxRadioGroup" Then
    ' Obtain the button
    Set btn = editor.Buttons(RadioButtonIndex)
    ' Set the value
    btn.SetFocus()
    btn.Checked = True
    ' Confirm the change
    Call grid.Keys("[Enter]")
  End If
End Sub

DelphiScript

procedure SetRadioButtonEditor(grid, view, rowIndex, columnId, RadioButtonIndex); forward;
procedure ActivateCellInplaceEditor(grid, view, rowIndex, columnId); forward;

procedure Main;
var
  p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');
      
  // Select radio buttons
  SetRadioButtonEditor(Grid, nil, 4, 'RadioGroupColumn', 1);
end;

// Working with the radio button editor
procedure SetRadioButtonEditor(grid, view, rowIndex, columnId, RadioButtonIndex);
var
  editor, btn : OleVariant;
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
    
  // Obtain the editor
  editor := view.Controller.EditingController.Edit;
  // Checks the editor's class name
  if editor.ClassName = 'TcxRadioGroup' then
  begin
    // Obtain the button
    btn := editor.Buttons[RadioButtonIndex];
    // Set the value
    btn.SetFocus();
    btn.Checked := True;
    // Confirm the change
    grid.Keys('[Enter]');
  end;
end;

C++Script, C#Script

function Main()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys["Process"]("MySampleApp");
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");
  
  // Select radio buttons
  SetRadioButtonEditor(Grid, null, 4, "RadioGroupColumn", 1);
}

// Working with the radio button editor
function SetRadioButtonEditor(grid, view, rowIndex, columnId, RadioButtonIndex)
{
  var editor, btn;

  // Obtain the view object
  if(view == null)
    view = grid["ActiveView"];

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
    
  // Obtain the editor
  editor = view["Controller"]["EditingController"]["Edit"];
  // Checks the editor's class name
  if(editor["ClassName"] == "TcxRadioGroup")
  {
    // Obtain the button
    btn = editor["Buttons"](RadioButtonIndex);
    // Set the value
    btn["SetFocus"]();
    btn["Checked"] = true;
    // Confirm the change
    grid["Keys"]("[Enter]");
  }
}

Working With Spin Box Editors

The spin box controls lets you change the value by pressing the Up Arrow or Down Arrow keys. You can change a value within a spin box cell by simulating the Up Arrow or Down Arrow keystrokes over the cell. Below is a sample script that demonstrates this approach.

Note that the spin box editor used by the QuantumGrid control lets users change the values with the Up and Down or Ctrl+Up or Ctrl+Down keystrokes. To determine if the Ctrl key is needed use the Properties.UseCtrlIncrement property of the edit object, which you obtain through the ViewObj.Controller.EditController.Edit property.

Example

View description

JavaScript

function Main()
{
  var p, Grid;

  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  DoUpSpinEditor(Grid, null, 4, 4);
  DoUpSpinEditor(Grid, null, 4, 4);
  DoDownSpinEditor(Grid, null, 4, 4);
}

// Increase the spin box value
function DoUpSpinEditor(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (strictEqual(view, null))
    view = grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);

  // If the editor is a spin box editor, then ...
  if (equal(view.Controller.EditingController.Edit.ClassName, "TcxSpinEdit"))
  {
    // ... check if a user should press Ctrl
    if (view.Controller.EditingController.Edit.Properties.UseCtrlIncrement)
      // Simulate the Ctrl-Up keystroke
      grid.Keys("^[Up]");
    else
      // Simulate the Up keystroke
      grid.Keys("[Up]");
  }
}

// Decrease the spin box value
function DoDownSpinEditor(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (strictEqual(view, null))
    view = grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
  
  // If the editor is a spin box editor, then ...
  if (equal(view.Controller.EditingController.Edit.ClassName, "TcxSpinEdit"))
  {
    // ... check if a user should press Ctrl
    if (view.Controller.EditingController.Edit.Properties.UseCtrlIncrement)
      // Simulate the Ctrl-Down keystroke
      grid.Keys("^[Down]");
    else
      // Simulate the Down keystroke
      grid.Keys("[Down]");
  }
}

JScript

function Main()
{
  var p, Grid;

  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  DoUpSpinEditor(Grid, null, 4, 4);
  DoUpSpinEditor(Grid, null, 4, 4);
  DoDownSpinEditor(Grid, null, 4, 4);
}

// Increase the spin box value
function DoUpSpinEditor(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (view == null)
    view = grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);

  // If the editor is a spin box editor, then ...
  if (view.Controller.EditingController.Edit.ClassName == "TcxSpinEdit")
  {
    // ... check if a user should press Ctrl
    if (view.Controller.EditingController.Edit.Properties.UseCtrlIncrement)
      // Simulate the Ctrl-Up keystroke
      grid.Keys("^[Up]");
    else
      // Simulate the Up keystroke
      grid.Keys("[Up]");
  }
}

// Decrease the spin box value
function DoDownSpinEditor(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (view == null)
    view = grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
  
  // If the editor is a spin box editor, then ...
  if (view.Controller.EditingController.Edit.ClassName == "TcxSpinEdit")
  {
    // ... check if a user should press Ctrl
    if (view.Controller.EditingController.Edit.Properties.UseCtrlIncrement)
      // Simulate the Ctrl-Down keystroke
      grid.Keys("^[Down]");
    else
      // Simulate the Down keystroke
      grid.Keys("[Down]");
  }
}

Python

def Main():

  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  
  DoUpSpinEditor(Grid, None, 4, 4)
  DoUpSpinEditor(Grid, None, 4, 4)
  DoDownSpinEditor(Grid, None, 4, 4)

# Increase the spin box value 
def DoUpSpinEditor(grid, view, rowIndex, columnId):
  # Obtain the view object
  if (view == None):
    view = grid.ActiveView

  # Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId)

  # If the editor is a spin box editor, then ...
  if (view.Controller.EditingController.Edit.ClassName == "TcxSpinEdit"):
    # ... check if a user should press Ctrl 
    if (view.Controller.EditingController.Edit.Properties.UseCtrlIncrement):
      # Simulate the Ctrl-Up keystroke
      grid.Keys("^[Up]")
    else:
      # Simulate the Up keystroke
      grid.Keys("[Up]")

# Decrease the spin box value 
def DoDownSpinEditor(grid, view, rowIndex, columnId):
  # Obtain the view object
  if (view == None):
    view = grid.ActiveView

  # Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
  
  # If the editor is a spin box editor, then ... 
  if (view.Controller.EditingController.Edit.ClassName == "TcxSpinEdit"):
    # ... check if a user should press Ctrl
    if (view.Controller.EditingController.Edit.Properties.UseCtrlIncrement):
      # Simulate the Ctrl-Down keystroke
      grid.Keys("^[Down]")
    else:
      # Simulate the Down keystroke
      grid.Keys("[Down]")

VBScript

Sub Main
  Set p = Sys.Process("MySampleApp")
  Set Grid = p.VCLObject("FormName").VCLObject("GridName")
  
  Call DoUpSpinEditor(Grid, Nothing, 4, 4)
  Call DoUpSpinEditor(Grid, Nothing, 4, 4)
  Call DoDownSpinEditor(Grid, Nothing, 4, 4)
End Sub

' Increase the spin box value
Sub DoUpSpinEditor(grid, view, rowIndex, columnId)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If

  ' Activate the in-place editor
  Call ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
  
  ' If the editor is a spin box editor, then ...
  If view.Controller.EditingController.Edit.ClassName = "TcxSpinEdit" Then
    ' ... check if a user should press Ctrl
    If view.Controller.EditingController.Edit.Properties.UseCtrlIncrement Then
      ' Simulate the Ctrl-Up keystroke
      grid.Keys("^[Up]")
    Else
      ' Simulate the Up keystroke
      grid.Keys("[Up]")
    End If
  End If
End Sub 

' Decrease the spin box value
Sub DoDownSpinEditor(grid, view, rowIndex, columnId)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If

  ' Activate the in-place editor
  Call ActivateCellInplaceEditor(grid, view, rowIndex, columnId)

  ' If the editor is a spin box editor, then ...
  If view.Controller.EditingController.Edit.ClassName = "TcxSpinEdit" Then
    ' ... check if a user should press Ctrl
    If view.Controller.EditingController.Edit.Properties.UseCtrlIncrement Then
      ' Simulate the Ctrl-Down keystroke
      grid.Keys("^[Down]")
    Else
      ' Simulate the Down keystroke
      grid.Keys("[Down]")
    End If
  End If
End Sub 

DelphiScript

procedure DoUpSpinEditor(grid, view, rowIndex, columnId); forward;
procedure DoDownSpinEditor(grid, view, rowIndex, columnId); forward;
procedure ActivateCellInplaceEditor(grid, view, rowIndex, columnId); forward;

procedure Main;
var
  p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');
  
  DoUpSpinEditor(Grid, nil, 4, 4);
  DoUpSpinEditor(Grid, nil, 4, 4);
  DoDownSpinEditor(Grid, nil, 4, 4);
end;

// Increase the spin box value
procedure DoUpSpinEditor(grid, view, rowIndex, columnId);
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;
  
  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
  
  // If the editor is a spin box editor, then ...
  if view.Controller.EditingController.Edit.ClassName = 'TcxSpinEdit' then
  begin
    // ... check if a user should press Ctrl
    if view.Controller.EditingController.Edit.Properties.UseCtrlIncrement then
      // Simulate the Ctrl-Up keystroke
      grid.Keys('^[Up]')
    else
      // Simulate the Up keystroke
      grid.Keys('[Up]');
  end;
end;

// Decrease the spin box value
procedure DoDownSpinEditor(grid, view, rowIndex, columnId);
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);

  // If the editor is a spin box editor, then ...
  if view.Controller.EditingController.Edit.ClassName = 'TcxSpinEdit' then
  begin
    // ... check if a user should press Ctrl
    if view.Controller.EditingController.Edit.Properties.UseCtrlIncrement then
      // Simulate the Ctrl-Down keystroke
      grid.Keys('^[Down]')
    else
      // Simulate the Down keystroke
      grid.Keys('[Down]');
  end;
end;

C++Script, C#Script

function Main()
{
  var p, Grid;
  
  p = Sys["Process"]("MySampleApp");
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");
  
  DoUpSpinEditor(Grid, null, 4, 4);
  DoUpSpinEditor(Grid, null, 4, 4);
  DoDownSpinEditor(Grid, null, 4, 4);
}

// Increase the spin box value
function DoUpSpinEditor(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (view == null)
    view = grid["ActiveView"];

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);

  // If the editor is a spin box editor, then ...
  if (view["Controller"]["EditingController"]["Edit"]["ClassName"] == "TcxSpinEdit")
  {
    // ... check if a user should press Ctrl
    if (view["Controller"]["EditingController"]["Edit"]["Properties"]["UseCtrlIncrement"])
      // Simulate the Ctrl-Up keystroke
      grid["Keys"]("^[Up]");
    else
      // Simulate the Up keystroke
      grid["Keys"]("[Up]");
  }
}

// Decrease the spin box value
function DoDownSpinEditor(grid, view, rowIndex, columnId)
{
  // Obtain the view object
  if (view == null)
    view = grid["ActiveView"];

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
  
  // If the editor is a spin box editor, then ...
  if (view["Controller"]["EditingController"]["Edit"]["ClassName"] == "TcxSpinEdit")
  {
    // ... check if a user should press Ctrl
    if (view["Controller"]["EditingController"]["Edit"]["Properties"]["UseCtrlIncrement"])
      // Simulate the Ctrl-Down keystroke
      grid["Keys"]("^[Down]");
    else
      // Simulate the Down keystroke
      grid["Keys"]("[Down]");
  }
}

Working With Drop-Down Editors

The QuantumGrid control offers various column types whose editors use drop-down windows. For example, the TcxComboBox editor uses a drop-down window containing the list of text items. Another example is the TcxCalcEdit editor that uses a drop-down window containing the calculator control.

All drop-down editor objects contain the following methods and properties, which you can use to show or hide the drop-down window:

  • DropDown - Method. Opens the drop-down window.
  • CloseUp(Accept) - Method. Closes the drop-down window. The Accept parameter specifies whether the editor saves or cancels the changes made within that window.
  • DroppedDown - Property. Specifies whether the drop-down window is open or not. Assigning True to this property opens the drop-down window; assigning False - closes the window.

To get access to the drop-down window, you can use the PopupWindow property of the editor object. This property will return the window object corresponding to the drop-down window. Then you can use methods, properties and actions of this object to simulate user actions over the window (see the sample below).

Note that the way in which you simulate user actions over the drop-down window depends on the window. For instance, if you open a drop-down list of a combo box editor, then to simulate keystrokes over this window, you should send keystrokes to the grid control. However, if you open a drop-down window of the calculator editor, then to simulate user actions over this calculator, you send keystrokes to the drop-down window.

The following code demonstrates how you can use the DropDown and CloseUp methods to open or hide the drop-down window of a cell that uses the combo box and calculator in-place editor. The sample also demonstrates how to simulate user actions over the drop-down window.

Example

View description

JavaScript

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

  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  // Open the combo box list
  OpenDropDownEditor(Grid, null, 4, "ComboColumn");
  // To simulate user actions over the combo box list,
  // send keystrokes to the grid
  Grid.Keys("[Down][Down]");
  // Close the drop-down window
  CloseDropDownEditor(Grid, null, 4, "ComboColumn", true);
  
  
  // Open the calculator drop-down editor
  w = OpenDropDownEditor(Grid, null, 4, "CalcColumn");
  // To simulate user actions over the calculator window,
  // send keystrokes to this window
  w.Keys("1");
  w.Keys("+");
  w.Keys("2");
  w.Keys("=");
  // Close the editor
  CloseDropDownEditor(Grid, null, 4, "CalcColumn", true);
}

// Open the drop-down window
function OpenDropDownEditor(grid, view, rowIndex, columnId)
{
  var editor;
  
  // Obtain the view object
  if (strictEqual(view, null))
    view = grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
    
  // Obtain the editor object
  editor = view.Controller.EditingController.Edit;
  // Check if the editor object contains the DropDown method
  if(aqObject.IsSupported(editor, "DropDown"))
  {
     // Invoke the drop-down window
    editor.DropDown();
    // Get the popup window
    return editor.PopupWindow;
  }
  else
    return null;
}

// Close the drop-down window
function CloseDropDownEditor(grid, view, rowIndex, columnId, accept)
{
  var editor;

  // Obtain the view object
  if(strictEqual(view, null))
    view = grid.ActiveView;
    
  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
   
  // Obtain the editor object
  editor = view.Controller.EditingController.Edit;
  // Check if the editor object contains the CloseUp method
  if(aqObject.IsSupported(editor, "CloseUp"))
    editor.CloseUp(accept); // Close the drop-down window
}

JScript

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

  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  // Open the combo box list
  OpenDropDownEditor(Grid, null, 4, "ComboColumn");
  // To simulate user actions over the combo box list,
  // send keystrokes to the grid
  Grid.Keys("[Down][Down]");
  // Close the drop-down window
  CloseDropDownEditor(Grid, null, 4, "ComboColumn", true);
  
  
  // Open the calculator drop-down editor
  w = OpenDropDownEditor(Grid, null, 4, "CalcColumn");
  // To simulate user actions over the calculator window,
  // send keystrokes to this window
  w.Keys("1");
  w.Keys("+");
  w.Keys("2");
  w.Keys("=");
  // Close the editor
  CloseDropDownEditor(Grid, null, 4, "CalcColumn", true);
}

// Open the drop-down window
function OpenDropDownEditor(grid, view, rowIndex, columnId)
{
  var editor;
  
  // Obtain the view object
  if (view == null)
    view = grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
    
  // Obtain the editor object
  editor = view.Controller.EditingController.Edit;
  // Check if the editor object contains the DropDown method
  if(aqObject.IsSupported(editor, "DropDown"))
  {
     // Invoke the drop-down window
    editor.DropDown();
    // Get the popup window
    return editor.PopupWindow;
  }
  else
    return null;
}

// Close the drop-down window
function CloseDropDownEditor(grid, view, rowIndex, columnId, accept)
{
  var editor;

  // Obtain the view object
  if(view == null)
    view = grid.ActiveView;
    
  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
   
  // Obtain the editor object
  editor = view.Controller.EditingController.Edit;
  // Check if the editor object contains the CloseUp method
  if(aqObject.IsSupported(editor, "CloseUp"))
    editor.CloseUp(accept); // Close the drop-down window
}

Python

def Main():

  # Obtain the grid object
  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  
  # Open the combo box list
  OpenDropDownEditor(Grid, None, 4, "ComboColumn")
  # To simulate user actions over the combo box list, 
  # send keystrokes to the grid
  Grid.Keys("[Down][Down]")
  # Close the drop-down window
  CloseDropDownEditor(Grid, None, 4, "ComboColumn", True)
  
  
  # Open the calculator drop-down editor
  w = OpenDropDownEditor(Grid, None, 4, "CalcColumn")
  # To simulate user actions over the calculator window, 
  # send keystrokes to this window
  w.Keys("1")
  w.Keys("+")
  w.Keys("2")
  w.Keys("=")
  # Close the editor
  CloseDropDownEditor(Grid, None, 4, "CalcColumn", True)

# Open the drop-down window
def OpenDropDownEditor(grid, view, rowIndex, columnId):
  
  # Obtain the view object
  if (view == None):
    view = grid.ActiveView

  # Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
    
  # Obtain the editor object
  editor = view.Controller.EditingController.Edit
  # Check if the editor object contains the DropDown method
  if(aqObject.IsSupported(editor, "DropDown")):
    # Invoke the drop-down window
    editor.DropDown()
    # Get the popup window
    return editor.PopupWindow
  else:
    return None

# Close the drop-down window
def CloseDropDownEditor(grid, view, rowIndex, columnId, accept):

  # Obtain the view object
  if(view == None):
    view = grid.ActiveView
    
  # Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
   
  # Obtain the editor object
  editor = view.Controller.EditingController.Edit
  # Check if the editor object contains the CloseUp method
  if(aqObject.IsSupported(editor, "CloseUp")):
    editor.CloseUp(accept) # Close the drop-down window

VBScript

Sub Main
  ' Obtain the grid object
  Set p = Sys.Process("MySampleApp")
  Set Grid = p.VCLObject("FormName").VCLObject("GridName")

  ' Open the combo box list
  Call OpenDropDownEditor(Grid, Nothing, 4, "ComboColumn")
  ' To simulate user actions over the combo box list,
  ' send keystrokes to the grid
  Call Grid.Keys("[Down][Down]")
  ' Close the drop-down window
  Call CloseDropDownEditor(Grid, Nothing, 4, "ComboColumn", True)
  
  ' Open the calculator drop-down editor
  Set w = OpenDropDownEditor(Grid, Nothing, 4, "CalcColumn")
  ' To simulate user actions over the calculator window,
  ' send keystrokes to this window
  Call w.Keys("1")
  Call w.Keys("+")
  Call w.Keys("2")
  Call w.Keys("=")
  ' Close the editor
  Call CloseDropDownEditor(Grid, Nothing, 4, "CalcColumn", True)
End Sub

' Open the drop-down window
Function OpenDropDownEditor(grid, view, rowIndex, columnId)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If

  ' Activate the in-place editor
  Call ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
    
  ' Obtain the editor object
  Set editor = view.Controller.EditingController.Edit
  ' Check if the editor object contains the DropDown method
  If aqObject.IsSupported(editor, "DropDown") Then
    ' Invoke the drop-down window
    Call editor.DropDown()
    ' Get the popup window
    Set OpenDropDownEditor = editor.PopupWindow
  Else
    OpenDropDownEditor = Nothing
  End If
End Function 

' Close the drop-down window
Sub CloseDropDownEditor(grid, view, rowIndex, columnId, accept)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If
    
  ' Activate the in-place editor
  Call ActivateCellInplaceEditor(grid, view, rowIndex, columnId)
   
  ' Obtain the editor object
  Set editor = view.Controller.EditingController.Edit
  ' Check if the editor object contains the CloseUp method
  If aqObject.IsSupported(editor, "CloseUp") Then
    editor.CloseUp(accept) ' Close the drop-down window
  End If
End Sub

DelphiScript

function OpenDropDownEditor(grid, view, rowIndex, columnId) : OleVariant; forward;
procedure CloseDropDownEditor(grid, view, rowIndex, columnId, accept); forward;
procedure ActivateCellInplaceEditor(grid, view, rowIndex, columnId); forward;

procedure Main;
var
  p, Grid, w : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');
  
  // Open the combo box list
  OpenDropDownEditor(Grid, nil, 4, 'ComboColumn');
  // To simulate user actions over the combo box list,
  // send keystrokes to the grid
  Grid.Keys('[Down][Down]');
  // Close the drop-down window
  CloseDropDownEditor(Grid, nil, 4, 'ComboColumn', True);
  
  // Open the calculator drop-down editor
  w := OpenDropDownEditor(Grid, nil, 4, 'CalcColumn');
  // To simulate user actions over the calculator window,
  // send keystrokes to this window
  w.Keys('1');
  w.Keys('+');
  w.Keys('2');
  w.Keys('=');
  // Close the editor
  CloseDropDownEditor(Grid, nil, 4, 'CalcColumn', True);
end;

// Open the drop-down window
function OpenDropDownEditor(grid, view, rowIndex, columnId) : OleVariant;
var
  editor, w : OleVariant;
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
  
  // Obtain the editor object
  editor := view.Controller.EditingController.Edit;
  // Check if the editor object contains the DropDown method
  if aqObject.IsSupported(editor, 'DropDown') then
  begin
     // Invoke the drop-down window
    editor.DropDown();
    // Get the popup window
    Result := editor.PopupWindow;
  end
  else
    Result := nil;
end;

// Close the drop-down window
procedure CloseDropDownEditor(grid, view, rowIndex, columnId, accept);
var
  editor : OleVariant;
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;
    
  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
   
  // Obtain the editor object
  editor := view.Controller.EditingController.Edit;
  // Check if the editor object contains the CloseUp method
  if aqObject.IsSupported(editor, 'CloseUp') then
    editor.CloseUp(accept); // Close the drop-down window
end;

C++Script, C#Script

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

  // Obtain the grid object
  p = Sys["Process"]("MySampleApp");
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");

  
  // Open the combo box list
  OpenDropDownEditor(Grid, null, 4, "ComboColumn");
  // To simulate user actions over the combo box list,
  // send keystrokes to the grid
  Grid["Keys"]("[Down][Down]");
  // Close the drop-down window
  CloseDropDownEditor(Grid, null, 4, "ComboColumn", true);
  
  // Open the calculator drop-down editor
  w = OpenDropDownEditor(Grid, null, 4, "CalcColumn");
  // To simulate user actions over the calculator window,
  // send keystrokes to this window
  w["Keys"]("1");
  w["Keys"]("+");
  w["Keys"]("2");
  w["Keys"]("=");
  // Close the editor
  CloseDropDownEditor(Grid, null, 4, "CalcColumn", true);
}

// Open the drop-down window
function OpenDropDownEditor(grid, view, rowIndex, columnId)
{
  var editor, w;
  
  // Obtain the view object
  if (view == null)
    view = grid["ActiveView"];

  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
    
  // Obtain the editor object
  editor = view["Controller"]["EditingController"]["Edit"];
  // Check if the editor object contains the DropDown method
  if(aqObject["IsSupported"](editor, "DropDown"))
  {
     // Invoke the drop-down window
    editor["DropDown"]();
    // Get the popup window
    return editor["PopupWindow"];
  }
  else
    return null;
}

// Close the drop-down window
function CloseDropDownEditor(grid, view, rowIndex, columnId, accept)
{
  var editor;

  // Obtain the view object
  if(view == null)
    view = grid["ActiveView"];
    
  // Activate the in-place editor
  ActivateCellInplaceEditor(grid, view, rowIndex, columnId);
   
  // Obtain the editor object
  editor = view["Controller"]["EditingController"]["Edit"];
  // Check if the editor object contains the CloseUp method
  if(aqObject["IsSupported"](editor, "CloseUp"))
    editor["CloseUp"](accept); // Close the drop-down window
}

See Also

Working With Developer Express QuantumGrid
Selecting Cells in Developer Express QuantumGrid
Activating In-place Editors in Developer Express QuantumGrid
Obtaining and Setting Cell Values in Developer Express QuantumGrid

Highlight search results