When testing applications that use the Developer Express QuantumGrid
controls, you may need to change values displayed in the grid’s cells.
You can do this in any of the following ways:
- By activating the cell’s in-place editor and simulating user input in it.
- By using the internal methods and properties of the QuantumGrid control.
Both methods require TestComplete to have access to internal methods and properties of the QuantumGrid control. For this purpose, the tested application must be compiled as an Open Application with debug information.
Below are descriptions and samples for both approaches. The sample code implies that the cell contains a box, to which text can be entered.
Simulating User Input
You can modify a grid cell value by inputting the desired value directly into the cell. In order for you to be able to do that, you first need to locate the desired cell within the grid, select it and activate its in-place editor. After the cell’s in-place editor is activated, you can “type” data in the cell by simulating keystrokes. The sample below demonstrates how you can do this.
The sample code contains the following routines:
Main
- The “main” routine of the sample. It obtains the scripting object that corresponds to the grid window and then calls the SetCellValue
routine to change the cell value. SetCellValue
- Simulates user input into a cell. The routine uses the following parameters:
- grid - The scripting object that corresponds to the tested grid control.
- view - The view object that is used to display the data. If this parameter is
Nothing
(VBScript), null
(JScript, C++Script, C#Script) or nil
(DelphiScript), the routine assumes that you are working with the view associated with the root level. - rowIndex - A zero-based index of the desired row.
- columnId - The caption of the desired column or the column index (zero-based) among other visible columns.
- newValue - Specifies the value to be entered in the cell. Since we “enter” values by simulating keystrokes, the newValue parameter must be a string value.
The routine performs the following actions:
- Checks if the view parameter is null and, if it is, uses the grid’s
ActiveView
property to obtain the view object that corresponds to the root level. - Calls the
ActivateCellInplaceEditor
script routine to activate the in-place editor within the desired cell. - Calls the
Keys
action to send the CTRL-A keystroke to the in-place editor. This selects the existing value, so that the subsequent input will replace the cell value. The Keys
action is provided by TestComplete. It is available for all window objects.
An alternative approach to selecting the cell contents is to call the internal Controller.EditingController.Edit.SelectAll
method of the view object. However, if this method is not used in the application’s source code, the compiler may exclude it from the application’s binary code. So, to call this method from scripts, make sure the method is used in the source code of your application. You can check whether the method is included into the application’s binary code by exploring the application in the Object Browser panel.
- Calls the
Keys
action to “enter” a new value into the inplace editor. The routine also sends the ENTER keystroke to the editor to confirm the input.
SelectGridCell
- Helper routine that is used to select the specified grid cell.
Note: To select the cell, the SelectGridCell
routine uses two internal properties of the view object that is used by the TcxGrid control (TCxGrid is a class name of the QuantumGrid component): FocusedRowIndex
and FocusedColumn
. These properties may be absent in the application’s binary code, so you may be unable to use them in your scripts. The problem is that Delphi’s (or C++Builder’s) smart linker excludes methods and properties that are not used within the application. So, it is possible that the mentioned properties are not included into the application’s executable, or the application provides limited access to them (for instance, a read/write property can be seen as read-only or write-only).
To solve the problem, you can create a virtual method in your code that will call the needed properties. For example, you can use the following code:
GetColumn
- Helper routine that returns the object that corresponds to the column of the desired cell.
Using TcxGrid Internal Methods and Properties
The QuantumGrid control can display several data levels. Each level has an associated view object that determines what data the level contains and how this data is displayed. The QunatumGrid library includes a view object that is bound to a database table or query as well as view objects that work with data stored in memory.
To set a value for the desired view, your script can select the cell and then assign the desired value to the Controller.FocusedColumn.EditValue
property of the view object. Selecting the cell is necessary in case the view is bound to a dataset -- the cell selection guarantees the data will be saved to the appropriate row and column of the database table.
If the view is not bound to a dataset, you can change the cell value by using the DataController.Values
property of the grid object. Setting a value with this property does not require the preliminary cell selection.
The mentioned properties are internal properties of the tested application and its objects. TestComplete can access these properties only if the tested application is compiled as an Open Application with debug information.
Also, these properties may be unavailable, if they are not used in the application’s source code, because the compiler automatically excludes those methods and properties that are not used in the application’s source code from the application’s executable. To solve the problem, you can add a virtual method to your application that will use the the Values
or FocusedColumn
properties, for example:
Since the method is virtual, the compiler will not exclude it from the executable and the executable will contain the properties.
Below are code samples that demonstrate how to use the mentioned properties:
Using the View.Controller.FocusedColumn.EditValue property
Using the View.DataController.Values property