Obtaining Selected Rows in Developer Express QuantumGrid

  May 03, 2007

When working with QuantumGrid controls, you may need to simulate the selection of several grid rows.

To obtain the selected rows, you can use the following internal methods of the TcxGrid object (TcxGrid is the class name of the QuantumGrid control):

  • ViewObj.DataController.GetSelectedCount - Returns the number of selected rows. This is a method of the view object (QuantumGrid can display data in several levels. Each level has an associated view object. It specifies what data the level displays and how it displays them).
  • ViewObj.DataController.GetSelectedRowIndex(SelectedIndex) - Returns the index of the selected row in the grid by its index in the collection of the view’s selected rows.

In order for TestComplete to be able to access the mentioned methods, the application under test must be compiled as an Open Applications with debug information.

Below is a sample script that demonstrates how you can use the internal methods of the QuantumGrid control to access selected rows. The sample code contains the following routines:

  • Main - The “main” routine of the sample. It obtains the scripting object that corresponds to the TcxGrid control, selects a number of grid rows and then calls the GetSelectedRows procedure that returns indexes of the selected rows. These indexes are then used to obtain cell values.
  • GetSelectedRows - This routine returns an array of selected rows’ indexes.

    The routine uses the following parameters:

    • grid - Specifies the tested grid.
    • view - Specifies the view object that contains the desired rows. If this parameter is Nothing (VBScript), null (JScript, C++Script, C#Script) or nil (DelphiScript), the routine assumes that you are working with the root level view.

    The routine performs the following actions:

    • Checks the view parameter and if it is null, the routine obtains the view object that corresponds to the root level of the grid.
    • Uses the view’s DataController.GetSelectedCount method to obtain the number of selected rows. Then, the routine creates the array of the appropriate size. Elements of this array will store the indexes of the selected rows. The GetSelectedRows function will return this array.
    • Iterates through selected rows and uses the view’s DataController.GetSelectedRowIndex method to obtain the indexes of the selected rows. Each index is stored to an element of the created array.
    • Returns the array.
  • SearchCellByValue - Searches a row by a cell value. In the given example, this routine is a helper, so I do not include its code. For more information on the routine, see Working With Developer Express Quantum Grid - Searching for Records.
  • SelectRow - Selects a row in the grid. In the given example, this routine is a helper, so I do not include its code. For more information on the routine, see Working With Developer Express QuantumGrid - Selecting Multiple Rows.
  • GetCellValue - Obtains the value of the specified cell. In the given example, this routine is a helper, so we do not include its code.