Working With Developer Express QuantumGrid - Expanding and Collapsing Rows
Test and Monitor | Posted April 26, 2007

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 Expand or 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:

  • Main - The “main” routine of the sample. It obtains the scripting object that corresponds to the tested grid object, calls the SearchCellByValue function to find the desired row and then calls the ExpandGridRow to expand the specified row (if possible).
  • SearchCellByValue - This function searches for a row that contains a cell with the specified text and if the row is found, the function returns its index. I do not include the routine code in this sample because this routine is just one of possible search alternatives. For more information on it, see “Working With Developer Express QuantumGrid - Searching for Records” article.
  • ExpandGridRow - Expands the specified grid row, if possible. The routine uses the following parameters:
    • grid - The scripting object that corresponds to the tested grid control.
    • view - The view object that contains the desired row. If this parameter is Nothing (VBScript), null (JScript, C++Script, C#Script) or nil (DelphiScript), the routine assumes that you are working with the view associated with the root level.
    • rowIndex - A zero-based index of the desired row.

    The routine performs the following actions:

    • Checks if the view parameter is null and, if it is, uses the grid’s ActiveView property to obtain the view object that corresponds to the root level.
    • Use the view object’s ViewData.Rows(rowIndex) property to obtain the row object that corresponds to the desired row. The rowIndex parameter specifies the zero-based index of the desired row within the view.
    • Determines whether the row can be expanded by checking the values of the row object’s Expandable property.
    • If the row is expandable, the routine calls the Expand method of the row object. This method has the ARecurse parameter. If it is True, the method also expands child nodes (if possible). If the parameter is False, the method expands only the row, for which it is called.
    • CollapseGridRow - Collapses the specified grid row, if possible. This routine performs the reverse action relative to the ExpandGridRow routine. To perform this task, it calls the Collapse method of the row object. This method uses the ARecurse parameter that specifies whether child groups are also collapsed.

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox