When testing applications that use the Developer Express XtraGrid controls, you may need to change values displayed in the grids cells. You can do this in any of the following ways:
- By simulating the user input into grid cells..
- By using the internal methods and properties of the XtraGrid control.
Below, I will explain how you can implement these approaches in TestComplete scripts. In your tests, you can use any of these approaches. The second approach - modifying the cell value programmatically - is easier; however, it assumes the user does not interact with controls and thus no corresponding events will be triggered. So, you may find that simulating user actions on the grid is more convenient.
Both approaches require access to internal properties, methods and objects of the XtraGrid control. To enable TestComplete to access them, you need to install and enable the .NET Open Application Support plug-in.
Simulating User Input
To modify grid cell values, you can input the new values directly in grid cells. To be able to do that, first, you need to select the desired cell within the grid and activate the cells in-place editor. I explained how to do this in my previous articles - Selecting Cells in Developer Express XtraGrid. and Activating and Closing In-place Editors in Developer Express XtraGrid.
When the cell is in the edit mode, you can type the desired value into it using the Keys
action applied to the grid control. Below is an example that illustrates how you can do it. This example works with the GridTutorials sample application that is shipped with the Developer Express XtraGrid Suite. The example contains four routines:
Main
- The scriptss main routine. It obtains the scripting object corresponding to the XtraGrid control and calls InputCellValue
to input new values into grids edit boxes.
InputCellValue
- Modifies the cell value by simulating the user input into the cell. It has the following parameters:
- Grid - Specifies the tested XtraGrid control.
- View - The grids view in which the cell resides. If the null value (
Nothing
in VBScript) is passed in this parameter, this means that the cell belongs to the grids main view.
- RowIndex - The zero-based index of the row (card) that contains the cell.
- ColumnId - The caption or its the zero-based index of the column (card field) that contains the cell.
- Value - The string to be typed into the cell.
The routines does the following:
- Selects the specified grid cell using the helper
ClickCell
routine.
- Calls the
ActivateCellEditor
routine to activate the cells edit mode.
- Types the new value into the cell using the
Keys
action.
- Calls
CloseEditor
to close the cell editor saving the changes made.
ClickCell
- Simulates a mouse click on the specified cell. For more information on this routine, refer to Selecting Cells in Developer Express XtraGrid.
GetColumn
- A helper function that returns the column object by the column caption or index.
ActivateCellEditor
- Activates the cells edit mode using the F2
shortcut.
CloseEditor
- Simulates the Enter
key press to apply changes made to the cell value.
Using Internal Methods of the XtraGrid Control
It is possible to set grid cell values using the SetRowCellValue
method of the grid view where the cell resides:
view
.SetRowCellValue(RowIndex, ColumnObj, Value)
This method assigns the value specified in the Value parameter to the cell specified by the row index and the column object. However, it does not select the specified cell.
The following example demonstrates how to use this method in scripts. It contains three routines:
Main
- Obtains the scripting object corresponding to the XtraGrid control and then uses the SetCellValue
routine to modify values of some grid cells..
SetCellValue
- Sets the new value of a grid cell. It has the following parameters:
- Grid - Specifies the tested XtraGrid control.
- View - The grids view in which the cell resides. If the null value (
Nothing
in VBScript) is passed in this parameter, this means that the cell belongs to the grids main view.
- RowIndex - The zero-based index of the row (card) that contains the cell.
- ColumnId - The caption or its the zero-based index of the column (card field) that contains the cell.
- Value - The string to be typed into the cell.
GetColumn
- A helper function that returns the column object by the column caption or index.