Getting Cell Values in Syncfusion GridControl
When testing an application with Syncfusion GridControl controls, you often need to get values held in grid cells. This article explains how you can do this and provides sample functions that you can use in your test scripts for this purpose.
Note: In order for TestComplete to be able to access grid cell values, it should have access to internal methods, properties 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.
To get the value stored in a particular grid cell, you can use the following statement:
GridObj.Item( RowIndex, ColIndex ).CellValue
Here, GridObj is the scripting object corresponding to the GridControl, RowIndex and ColIndex are zero-based indexes of the cells row and column. This property returns the .NET object corresponding to the cell value.
Remember that some simple .NET values, for example,
Boolean and others, are OLE-compatible and thus can be used in scripts directly. To get OLE-compatible values of
DateTime and enumeration values, you should use the
OleValue property added to these objects by TestComplete. To work with complex object values, use their internal properties and methods.
In certain cases, the cell value may significantly differ from the actual text displayed in the cell. For example, the GridControl may display values with a special formatting applied. Also, it may be configured to display date values as Tuesday, March 19, 2007 instead of 3/19/2007, currency values as $123,456.78 instead of 123456.78, and so on. In this case, you will most likely want to get the actual text displayed in grid cells rather than the cell values. You can do this by using the
FormattedText property instead of the
GridObj.Item( RowIndex, ColIndex ).FormattedText.OleValue
(We use the
OleValue property of the returned string to make it OLE-compatible.)
Below is an example that demonstrates how you can get the GridControl cell values and display text. The example works with the GridControlSort sample application that comes with Syncfusion Essential Studio library and resides in the following folder:
The script contains three routines:
Main is the main script routine. It obtains the scripting object corresponding to the GridControl and post data of the first grid row to the test log.
GetCellText return the value of the specified grid cell and the cells display text, respectively. Both functions have the same parameters:
- Grid -- Specifies the tested GridControl object.
- RowIndex and ColIndex -- The zero-based indexes of the cells row and column.