When testing applications that use the Syncfusion GridControl controls, you may need to change values displayed in the grid’s 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 GridControl object.
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 over the grid is more convenient.
Both approaches require access to internal properties, methods and objects of the GridControl object. 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 cell’s in-place editor. I explained how to do this in my previous articles – Selecting Cells in Syncfusion GridControl.
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 GridControlSort sample application that comes with Syncfusion Essential Studio library and resides in the following folder:
<Essential Studio>WindowsGrid.WindowsSamplesFeatureSamplesGridControlSort
The example contains three routines:
Mainis the scripts’s “main” routine. It obtains the scripting object corresponding to the GridControl and inputs new data into the first row’s cells.InputCellValuemodifies the cell value by simulating user input into the cell. It has the following parameters:- Grid — Specifies the tested GridControl.
- RowIndex and ColIndex — The zero-based indexes of the cell’s row and column.
- Value — The string to be “typed” into the cell.
- Selects the specified grid cell using the helper ClickCell routine.
- Activates the cell’s edit mode with the F2 key press.
- “Types” the new value into the cell using the
Keysaction. - Simulates the Enter key press to save the changes made and close the editor.
- Grid — Specifies the tested GridControl.
ClickCellsimulates a mouse click on the specified grid cell. For more information on this routine, please see Selecting Cells in Syncfusion GridControl.
Using GridControl Internal Methods
It is possible to set grid cell values using the CellValue, Text and FormattedText properties of an object that corresponds to a GridControl cell. You can use the CellValue property to specify the cell value, the Text property to specify the cell value by its string representation, and the FormattedText property to set the new cell value that corresponds to the specified formatted text.
Note that when using the CellValue property to modify the cell value of a complex type, such as System.DateTime, System.Drawing.Color and others, you need to create an instance of the corresponding .NET class. For more information on how to do this, see the “Calling Functions From .NET Assemblies” topic in TestComplete help. As an alternative, you can use the Text or FormattedText properties to specify the desired value by its text representation. The specified string will be parsed and converted to the cell value.
Below is an example that demonstrates how you can set grid cell values from scripts. The script contains the following routines:
Mainis the scripts’s “main” routine. It obtains the scripting object corresponding to the GridControl and modifies values of some cells.SetCellValuesets the value of the specified cell. It has the following parameters:- Grid — The tested GridControl object.
- RowIndex and ColIndex — The zero-based indexes of the cell’s row and column.
- Value — Specifies the cell’s new value.
- Grid — The tested GridControl object.
SetCellTextsets the value of the specified cell. This routine is different than theSetCellValue, in that the cell value is specified by its text representation in the format used by the cell. For example, “Tuesday, March 19, 2007” or “$123,456.78”.CreateDateTimeis a helper function that creates a new instance of the .NET System.DateTime class with the specified year, month, day, hour, minute and seconds. In order for this function to run successfully, the TestComplete’s .NET Classes Support plug-in must be installed and enabled.