Expanding and Collapsing Rows in Developer Express QuantumGrid

Applies to TestComplete 15.70, last modified on December 17, 2024

The QuantumGrid control supports hierarchical data representation. If the grid displays data of multiple nested data tables, then each data row can have child rows containing data associated with this row. To view the child data, the user needs to expand its parent row. The grid data can also be grouped by one or several columns, so the individual rows are organized into groups. This topic explains how you can expand and collapse rows and groups in the QuantumGrid control from your test scripts:

In order for TestComplete to be able to perform these actions, the following conditions must be met: Note also, that the compiler can exclude methods and properties that are not called in the application’s source code from the application’s binary code, so these methods and properties are unavailable to TestComplete (see Object Properties, Fields and Methods That Are Unavailable to TestComplete). To solve the problem, make sure that the desired methods and properties are used in the application’s source code. For instance, you can add a virtual method to your application that calls the desired methods and properties (the compiler does not exclude virtual methods).

When testing Developer Express QuantumGrid controls, use specific methods and properties of the corresponding DevExpressQuantumGrid object. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with an object’s properties and methods from your scripts. However, when testing a QuantumGrid control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

Using the DevExpressQuantumGrid.Expand and Collapse Actions

The DevExpressQuantumGrid object has special methods and properties to work with expandable rows of both types. To determine whether the row is a group row, check the ViewObj.ViewData.Rows(RowIndex).HasCells property of the row object. Group rows do not have cells, so this property will be False for them.

Group rows are expanded and collapsed by the ExpandGroup and CollapseGroup actions. The current state of a group row can be obtained with the wGroupExpanded property, which returns True if the group is currently expanded.

Similarly, data rows are expanded and collapsed by the Expand and Collapse actions. The current state of a row is returned by the wExpanded property. 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, you can perform a click upon the row indicator with the ClickRowIndicator action or assign True to the ViewObj.ViewData.Rows(rowIndex).Focused property of the corresponding “native” row object.

The following example illustrates how you can expand and collapse ordinary and group rows using actions provided by TestComplete:

JavaScript, JScript

function Main ()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");

  // Check whether the grid has group rows
  if (Grid.wGroupCount > 0)
    // Expand the second group
    Grid.ExpandGroup(1);

  // Expand the third data row
  Grid.Expand(2);

  aqUtils.Delay(2000);

  // Collapse the third data row
  Grid.Collapse(2);

  if (Grid.wGroupCount > 0)
    // Collapse the second group
    Grid.CollapseGroup(1);
}

Python

def Main():

  # Obtain the grid object 
  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")

  # Check whether the grid has group rows
  if (Grid.wGroupCount > 0):
    # Expand the second group
    Grid.ExpandGroup(1)

  # Expand the third data row 
  Grid.Expand(2)

  aqUtils.Delay(2000)

  # Collapse the third data row
  Grid.Collapse(2)

  if (Grid.wGroupCount > 0):
    # Collapse the second group
    Grid.CollapseGroup(1)

VBScript

Sub Main
  Dim p, Grid

  ' Obtain the grid object
  Set p = Sys.Process("MySampleApp")
  Set Grid = p.VCLObject("FormName").VCLObject("GridName")

  ' Check whether the grid has group rows
  If Grid.wGroupCount > 0 Then
    ' Expand the second group
    Grid.ExpandGroup(1)
  End If

  ' Expand the third data row
  Grid.Expand(2)

  aqUtils.Delay(2000)

  ' Collapse the third data row
  Grid.Collapse(2)

  If Grid.wGroupCount > 0 Then
    ' Collapse the second group
    Grid.CollapseGroup (1)
  End If
End Sub

DelphiScript

procedure Main;
var p, Grid: OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');
  
  // Check whether a grid has group rows
  if Grid.wGroupCount > 0 then
    // Expand the second group
    Grid.ExpandGroup (1);
  
  // Expand the third data row
  Grid.Expand(2);

  aqUtils.Delay(2000);

  // Collapse the third data row
  Grid.Collapse(2);

  if Grid.wGroupCount > 0 then
    // Collapse the second group
    Grid.CollapseGroup(1);
end;

C++Script, C#Script

function Main ()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys["Process"]("MySampleApp");
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");

  // Check whether the grid has group rows
  if (Grid["wGroupCount"] > 0)
    // Expand the second group
    Grid["ExpandGroup"](1);

  // Expand the third data row
  Grid["Expand"](2);

  aqUtils["Delay"](2000);

  // Collapse the third data row
  Grid["Collapse"](2);

  if (Grid["wGroupCount"] > 0)
    // Collapse the second group
    Grid["CollapseGroup"](1);
}

Using TcxGrid Internal Methods and Properties

Another way to expand and collapse grid rows is to use the internal methods of the TcxGrid object (TcxGrid is the class name of QUantumGrid controls). To expand or collapse the row, you can write script code that will perform the following actions:

  • Find the desired row in the grid. You can find the desired row using one of the methods mentioned in the Searching for Records in Developer Express QuantumGrid topic.
  • 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. See Getting Views in Developer Express QuantumGrid for more information.
  • 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 ViewObj.ViewData.Rows(rowIndex).HasCells property of the row object. Group rows do not have cells, so this property will be False for them.

The following sample demonstrates how to use the mentioned internal methods and properties to expand and collapse grid rows:

Example

View description

JavaScript

function Main()
{
  var p, Grid, ColumnName, ColumnValue, r;

  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  // Search for a row
  ColumnName = "MyColumn";
  ColumnValue = "MyValue";
  r = FindRow (Grid, ColumnName, ColumnValue, 0);
  // Expand the row
  ExpandGridRow(Grid, null, r);
  // To collapse the row, use the following code:
  // CollapseGridRow(Grid, null, r);
}

// Expand a row
function ExpandGridRow(grid, view, rowIndex)
{
  let Row;
  
  // Obtain the view object
  if (strictEqual(view, null))
    view = grid.ActiveView;

  // Get the row object
  Row = view.ViewData.Rows(rowIndex);
 
  // Check if the row can be expanded
  if (Row.Expandable)
    Row.Expand(false); // Expand the row
}

// Collapse a row
function CollapseGridRow(grid, view, rowIndex)
{
  var Row;
  
  // Obtain the view object
  if (strictEqual(view, null))
    view = grid.ActiveView;

  // Get the row object
  Row = view.ViewData.Rows(rowIndex);
  
  // Check if the row can be collapsed or expanded
  if (Row.Expandable)
    Row.Collapse(false); // Collapse the row
}

JScript

function Main()
{
  var p, Grid, ColumnName, ColumnValue, r;

  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  
  // Search for a row
  ColumnName = "MyColumn";
  ColumnValue = "MyValue";
  r = FindRow (Grid, ColumnName, ColumnValue, 0);
  // Expand the row
  ExpandGridRow(Grid, null, r);
  // To collapse the row, use the following code:
  // CollapseGridRow(Grid, null, r);
}

// Expand a row
function ExpandGridRow(grid, view, rowIndex)
{
  var Row;
  
  // Obtain the view object
  if (view == null)
    view = grid.ActiveView;

  // Get the row object
  Row = view.ViewData.Rows(rowIndex);
 
  // Check if the row can be expanded
  if (Row.Expandable)
    Row.Expand(false); // Expand the row
}

// Collapse a row
function CollapseGridRow(grid, view, rowIndex)
{
  var Row;
  
  // Obtain the view object
  if (view == null)
    view = grid.ActiveView;

  // Get the row object
  Row = view.ViewData.Rows(rowIndex);
  
  // Check if the row can be collapsed or expanded
  if (Row.Expandable)
    Row.Collapse(false); // Collapse the row
}

Python

def Main():

  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  
  # Search for a row
  ColumnName = "MyColumn"
  ColumnValue = "MyValue"
  r = FindRow (Grid, ColumnName, ColumnValue, 0)
  # Expand the row
  ExpandGridRow(Grid, None, r)
  # To collapse the row, use the following code:
  # CollapseGridRow(Grid, None, r)

# Expand a row
def ExpandGridRow(grid, view, rowIndex):
  
  # Obtain the view object
  if (view == None):
    view = grid.ActiveView

  # Get the row object 
  Row = view.ViewData.Rows(rowIndex)
 
  # Check if the row can be expanded
  if (Row.Expandable):
    Row.Expand(False) # Expand the row 

# Collapse a row
def CollapseGridRow(grid, view, rowIndex):
  
  # Obtain the view object
  if (view == None):
    view = grid.ActiveView

  # Get the row object
  Row = view.ViewData.Rows(rowIndex)
  
  # Check if the row can be collapsed or expanded
  if (Row.Expandable):
    Row.Collapse(False) # Collapse the row

VBScript

Sub Main
  Dim p, Grid, ColumnName, ColumnValue, r
  
  Set p = Sys.Process("MySampleApp")
  Set Grid = p.VCLObject("FormName").VCLObject("GridName")
  
  ' Search for a row
  ColumnName = "MyColumn"
  ColumnValue = "MyValue"
  r = FindRow (Grid, ColumnName, ColumnValue, 0)
  ' Expand the row
  Call ExpandGridRow(Grid, Nothing, r)
  ' To collapse the row, use the following code:
  ' Call CollapseGridRow(Grid, Nothing, r)
End Sub

' Expand a row
Sub ExpandGridRow(grid, view, rowIndex)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If
  
  ' Get the row object
  Set Row = view.ViewData.Rows(rowIndex)
  
  ' Check if the row can be expanded
  If Row.Expandable Then
    ' Expand the row
    Row.Expand(false)
  End If
End Sub 

' Collapse a row
Sub CollapseGridRow(grid, view, rowIndex)
  ' Obtain the view object
  If view Is Nothing Then
    Set view = grid.ActiveView
  End If
  
  ' Get the row object
  Set Row = view.ViewData.Rows(rowIndex)
  
  ' Check if the row can be collapsed or expanded
  If Row.Expandable Then
    ' Collapse the row
    Row.Collapse(false)
  End If
End Sub 

DelphiScript

procedure ExpandGridRow(grid, view, rowIndex); forward;
procedure CollapseGridRow(grid, view, rowIndex); forward;
function FindRow (Grid, ColumnId, SearchString, ViewId : OleVariant = 0): OleVariant; forward;

procedure Main;
var
  p, Grid, ColumnName, ColumnValue, r : OleVariant;
begin
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');

  // Search for a row
  ColumnName := 'MyColumn';
  ColumnValue := 'MyValue';
  r := FindRow (Grid, ColumnName, ColumnValue, 0);
  // Expand the row
  ExpandGridRow(Grid, nil, r);
  // To collapse the row, use the following code:
  // CollapseGridRow(Grid, nil, r);
end;

// Expand a row
procedure ExpandGridRow(grid, view, rowIndex);
var
  Row : OleVariant;
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;

  // Get the row object
  Row := view.ViewData.Rows(rowIndex);
 
  // Check if the row can be expanded
  if Row.Expandable then
    Row.Expand(False); // Expand the row
end;

// Collapse a row
procedure CollapseGridRow(grid, view, rowIndex);
var
  Row : OleVariant;
begin
  // Obtain the view object
  if view = nil then
    view := grid.ActiveView;

  // Get the row object
  Row := view.ViewData.Rows(rowIndex);
  
  // Check if the row can be collapsed or expanded
  if Row.Expandable then
    Row.Collapse(False); // Collapse the row
end;

C++Script, C#Script

function Main()
{
  var p, Grid, ColumnName, ColumnValue, r;

  p = Sys["Process"]("MySampleApp");
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");
  
  // Search for a row
  ColumnName = "MyColumn";
  ColumnValue = "MyValue";
  r = FindRow (Grid, ColumnName, ColumnValue, 0);
  // Expand the row
  // ExpandGridRow(Grid, null, r);
  // To collapse the row, use the following code:
  CollapseGridRow(Grid, null, r);
}

// Expand a row
function ExpandGridRow(grid, view, rowIndex)
{
  var Row;
  
  // Obtain the view object
  if (view == null)
    view = grid["ActiveView"];

  // Get the row object
  Row = view["ViewData"]["Rows"](rowIndex);
 
  // Check if the row can be expanded
  if (Row["Expandable"])
    Row["Expand"](false); // Expand the row
}

// Collapse a row
function CollapseGridRow(grid, view, rowIndex)
{
  var Row;
  
  // Obtain the view object
  if (view == null)
    view = grid["ActiveView"];

  // Get the row object
  Row = view["ViewData"]["Rows"](rowIndex);
  
  // Check if the row can be collapsed or expanded
  if (Row["Expandable"])
    Row["Collapse"](false); // Collapse the row
}

See Also

Working With Developer Express QuantumGrid
Getting Views in Developer Express QuantumGrid
Collapse Action (Specific to DevExpressQuantumGrid Controls)
CollapseGroup Action (Specific to DevExpressQuantumGrid Controls)
Expand Action (Specific to DevExpressQuantumGrid Controls)
ExpandGroup Action (Specific to DevExpressQuantumGrid Controls)

Highlight search results