Working With Drop-Down Editors in Developer Express QuantumGrid

  April 23, 2007

The Developer Express QuantumGrid control offers a lot of different
column types. Each column type provides a specific in-place editor for
modifying cell values. There are 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. This article explains how you can work with these
drop-down editors in TestComplete scripts.

To work with drop-down editors, TestComplete should have access to the internal methods and properties of the TcxGrid object (TcxGrid is the class name of the QuantumGrid control). That is, the tested application must be compiled as an Open Application with debug information.

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 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. If a column uses specific drop-down editor, the grid creates this specific 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. 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.

The sample contains the following routines:

  • Main - The “main” routine of the sample. It obtains the scripting object that corresponds to the tested grid control and then calls the OpenDropDownEditor and CloseDropDownEditor editor for the combo box and calculator columns and simulates user actions over the drop-down windows.
  • OpenDropDownEditor - Open a drop-down editor of the specified cell. The routine uses the following parameters:
    • grid - Specifies the object that provides scripting access to the tested grid control.
    • view - Specifies the view that contains the desired cell. If this parameter is Nothing (VBScript), null (JScript, C++Script, C#Script) or nil (DelphiScript), the routine assumes you are working with the root level view.
    • rowIndex - Specifies the row index (zero-based) of the desired cell.
    • columnId - Specifies the caption or index of the desired column. The column index is zero-based. It specifies the column position among other visible columns.

    The routine performs the following actions:

    • Checks the view parameter value and obtains the view object, if needed.
    • Calls the ActivateCellInplaceEditor routine to activate the in-place editor.
    • Obtains the editor object.
    • Checks if the editor object contains the DropDown method (if the object does not contain this method, it is not an editor object that has a drop-down window). To perform the check, we use the BuiltIn.IsSupported method.
    • If the editor has a drop-down window, the routine calls the editor’s DropDown method to show this drop-down window.
    • Then the routine uses the editor’s PopupWindow property to obtain the test object corresponding to the popup window.
  • CloseDropDownEditor - Closes the drop-down editor. The routine code is very similar to the code of the OpenDropDownEditor function. CloseDropDownEditor uses the same parameters as OpenDropDownEditor plus one extra parameter: accept. It can be True or False and it specifies whether the editor should accept or cancel the entered value.
  • ActivateCellInplaceEditor - Helper routine used to activate the in-place editor of the specified cell. We do not include the source code for this routine into this sample.