Working With Developer Express QuantumGrid - Selecting Multiple Rows
When working with Developer Express QuantumGrid controls, you may need to simulate selecting several grid rows. This article gives examples of how you can do this.
You can select multiple cells in the following ways:
- By simulating CTRL- or SHIFT-clicks over the desired records (CTRL-click selects one row; SHIFT-click selects all rows in the range from the currently selected row to the row where the click occurs).
- By using the internal properties of the TcxGrid object (TcxGrid is the class name of the QuantumGrid control).
To perform these actions, TestComplete should have access to the internal methods and properties of the TcxGrid object (TcxGrid is the class name of the QuantumGrid control). That is, the tested application must be compiled as an Open Application with debug information.
Using the internal methods and properties seems to be a simpler approach, since simulating the mouse click over rows requires calculating the row coordinates within the grid window.
To mark a particular row as selected, do the following:
- Use the
ViewData.Rows(rowIndex) property of the view object to obtain the row object that corresponds to the desired row (QuantumGrid can display data in several levels. What data is displayed on a level and how they are displays is specified by view objects).
- Assign True to the
Selected property of this row object.
Note: multiple selection is possible only if the view object’s
OptionsSelection.MultiSelect property is set to True. If you are not sure whether the tested grid supports multi-selection, ask the application developer about this. You can also check this yourself by selecting several records with CTRL- or SHIFT-click.
The following code demonstrates how you can use these properties to select and unselect grid rows. The sample code contains the following routines:
Main - The “main” routine of the sample. It obtains the scripting object that corresponds to the tested grid object and then calls the
SelectCellByValue routine to find the desired row and the
SelectRow routine to select this row.
Note: Selecting a row does not remove the selection from the current grid row.
SearchCellByValue - This routine is used to obtain the index of the row that contains a cell storing the specified value. I do not include the code of this routine in the sample listing below since this routine is just only one of several possible variants of getting the row index. For more information on it, see Working With Developer Express QuantumGrid - Searching for Records article.
When writing the code that will locate the desired rows, do not use the approaches that simulates keystrokes over the grid window, since pressing a key over the grid window removes the selection from the selected rows.
SelectRow - This routine is used to select the specified grid row. It uses the following parameters:
- grid - Specifies the tested grid object.
- view - Specifies the view object that is used to display data (QuantumGrid can display data in several levels. A view object defines what data a level displays and how it displays them).
If this parameter is
null (JScript, C++Script, C#Script) or
nil (DelphiScript), the routine will use the view object that corresponds to the root level.
- row - Specifies the index of the row to be selected. The index is zero-based.
Here is the sample code:
To unselect a routine from script, you can assign False to the
Selected property of the row object. Below is a code snippet that demonstrates this: