Working With Developer Express QuantumGrid - Expanding and Collapsing Rows
The Developer Express QuantumGrid control can contain expandable rows. There are two types of expandable rows:
- Group rows. They appear when the grid contents are grouped by one or several columns.
- Ordinary rows that have child data. The QuantumGrid control can display data in several levels. If a child level contains rows associated with the parent row, then a user can expand this parent row to view the child data.
You can expand or collapse a particular grid row by simulating a mouse click over the “+” or “-” button that is displayed on the left of the row, or using internal methods and properties of the TcxGrid object (TcxGrid is the class name of the QuantumGrid control). To simulate a click you have to calculate the coordinates of the click and this may not be easily done since you need to take into account the scrolling distance, position of the row relative to the grid’s bounds, the level on which the row is displayed and other factors. Using the internal methods and properties seem to be the easiest solution.
To expand or collapse the row, you can write TestComplete script that will perform the following actions:
- Find the desired row in the grid.
- Obtain the row object that provides a scripting interface to the row. You can do this by using the Row property of the view object (QuantumGrid can display data in several levels. View objects are associated with levels, they define what data the level displays and how it displays them.
- Use the
Collapse methods of the appropriate row object to expand or collapse the row, respectively.
Note that only group rows and rows that have child data can be expanded and collapsed. To determine whether a row can be expanded or collapsed, use the
Expandable property of the row object.
To check if the row is already expanded (or collapsed), use the
Expanded property of the row object.
To determine whether the row is a group row, check the
HasCells property of the row object. Group rows do not have cells, so this property will be False for them.
If the row to be expanded has child data, then you may need to focus this row in order for the grid to display the appropriate child data. To focus the row, assign True to the
Focused property of the row object.
In order for TestComplete to be able to access the internal methods of the QuantumGrid control, the tested application must be compiled as an Open Application with debug information.
The following sample demonstrates how to use the mentioned internal methods and properties to expand and collapse grid rows. The sample contains the following routines: