Getting Cell Values in Developer Express XtraGrid

  May 14, 2007

When testing an application with the Developer Express XtraGrid control, 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 XtraGrid control. 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 methos of the grid’s view in which the desired cell resides:

view.GetRowCellValue (RowIndex, ColumnObj)

The RowIndex parameter of this method is the zero-based index of the grid row (card) containing the desired cell. The ColumnObj parameter specifies the scripting object corresponding to the grid column that contains the cell. The method returns the .NET object corresponding to the cell value. Some “simple” values, for example, Integer, Boolean and others, are OLE-compatible and thus can be used in scripts directly. To get OLE-compatible values of String, Decimal, 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.

The XtraGrid control can display values using a special formatting applied. For example, it can be configured to use regional options to display different kinds of values, for example: “Tuesday, March 19, 2007” instead of “3/19/2007” (for date values), $1234.00 instead of 1234 (for currency values), and so on. In this case you will more likely want to get the actual text displayed in grid cells rather than cell values. The following method of the grid’s view lets you obtain the cell text:

view.GetRowCellText (RowIndex, ColumnObj)

Below is an example that demonstrates how you can the mentioned methods to get the XtraGrid cell values and display text. The example works with the GridTutorials sample application that comes with the Developer Express XtraGrid Suite. The script contains the following routines:

  • Main - The “main” script routine. It obtains the scripting object corresponding to the XtraGrid control, calls the GetCellValue and GetCellText functions to obtain a grid cell value
    and text and posts these values to the test log.
  • GetCellValue - Returns the value of the specified grid cell.
  • GetCellText - Returns the text displayed in the specified grid cell.

    The GetCellValue and GetCellText functions have the same parameters:

    • Grid - Specifies the tested XtraGrid control.
    • View - The grid’s view in which the cell resides. If the null value (Nothing in VBScript, nil in DelphiScript, null in JScript, C++Script and C#Script) is passed in this parameter, this means that the cell belongs to the grid’s main view.
    • RowIndex - The zero-based index of the row (card) that contains the cell.
    • ColumnId - The caption or its visible index of the column (card field) that contains the cell.
  • GetColumn - A helper function that returns the column object specified by its caption or position in the grid.