Getting Views in Developer Express QuantumGrid

Applies to TestComplete 15.47, last modified on January 20, 2023

The QuantumGrid control can display data in multiple levels. Each grid level can have one or more views, which displays data in a table, banded, card or other form. When working with the QuantumGrid control from scripts, you need to specify the view that contains the data you are going to work with. This topic explains how you can access grid views from 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.wChildLevel Property

Methods and properties of the DevExpressQuantumGrid object let you work with data of top-level views. To access child levels and work with child data, you can use the wChildLevel property. This property returns the DevExpressQuantumGridLevel object that represents the specified child level, or the null value (null in JavaScript, JScript, C#Script and C++Script, None in Python, Nothing in VBScript, nil in DelphiScript), if the row does not contain child data. Similarly, you can access a grand-child level by using the wChildLevel property applied to a child level object, and so on.

Each grid level can display one or more views. Therefore, all specific methods and properties of the DevExpressQuantumGrid and DevExpressQuantumGridLevel objects have the View that lets you specify the view you are going to work with. The wViewCount property lets you determine the number of views in the given grid level.

Below is an example that illustrates how you can process grid data displayed in several views:

Example

View description

JavaScript

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

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

  // Locate a row by its cell value
  ColumnName = "MyColumn";
  ColumnValue = "MyValue";
  RowIndex = FindRow (Grid, ColumnName, ColumnValue);

  // Check if the row has child data
  ChildLevel = Grid.wChildLevel (RowIndex);
  if (!strictEqual(ChildLevel, null))
  {
    // Post the number of rows in child views to the log
    for (let ViewIdx=0; ViewIdx<ChildLevel.wViewCount; ViewIdx++)
      Log.Message(ChildLevel.wView(ViewIdx) + ": " + ChildLevel.wRowCount(ViewIdx) + " rows.");
  }
}

function FindRow (Level, ColumnId, Value, ViewId)
{
  // If the ViewId parameter is not specified,
  // initialize it with the default value
  if (strictEqual(ViewId, undefined))
    ViewId = 0;

  // Iterate through the rows
  for (let i=0; i<Level.wRowCount(ViewId); i++)
    // Check the cell value in the specified column
    if (equal(Level.wValue(i, ColumnId, ViewId), Value))
      return i; // Row is found

  return -1; // Row is not found
}

JScript

function Main ()
{
  var p, Grid, ColumnName, ColumnValue, ChildLevel, RowIndex, ViewIdx;

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

  // Locate a row by its cell value
  ColumnName = "MyColumn";
  ColumnValue = "MyValue";
  RowIndex = FindRow (Grid, ColumnName, ColumnValue);

  // Check if the row has child data
  ChildLevel = Grid.wChildLevel (RowIndex);
  if (ChildLevel != null)
  {
    // Post the number of rows in child views to the log
    for (ViewIdx=0; ViewIdx<ChildLevel.wViewCount; ViewIdx++)
      Log.Message(ChildLevel.wView(ViewIdx) + ": " + ChildLevel.wRowCount(ViewIdx) + " rows.");
  }
}

function FindRow (Level, ColumnId, Value, ViewId)
{
  // If the ViewId parameter is not specified,
  // initialize it with the default value
  if (typeof(ViewId) == "undefined")
    ViewId = 0;

  // Iterate through the rows
  for (var i=0; i<Level.wRowCount(ViewId); i++)
    // Check the cell value in the specified column
    if (Level.wValue(i, ColumnId, ViewId) == Value)
      return i; // Row is found

  return -1; // Row is not found
}

Python

def Main ():

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

  # Locate a row by its cell value
  ColumnName = "MyColumn"
  ColumnValue = "MyValue"
  RowIndex = FindRow (Grid, ColumnName, ColumnValue)

  # Check if the row has child data 
  ChildLevel = Grid.wChildLevel (RowIndex)
  if (ChildLevel != None):
    # Post the number of rows in child views to the log
    for ViewIdx in range(0, ChildLevel.wViewCount-1):
      Log.Message(ChildLevel.wView[ViewIdx] + ": " + ChildLevel.wRowCount[ViewIdx] + " rows.")

def FindRow (Level, ColumnId, Value, ViewId):
  # If the ViewId parameter is not specified,
  # initialize it with the default value
  if (typeof(ViewId) == "undefined"):
    ViewId = 0

  # Iterate through the rows
  for i in range(0, Level.wRowCount(ViewId)-1):
    # Check the cell value in the specified column 
    if (Level.wValue[i, ColumnId, ViewId] == Value):
      return i # Row is found

  return -1 # Row is not found

VBScript

Sub Main
  Dim p, Grid, ColumnName, ColumnValue, ChildLevel, RowIndex, ViewIdx

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

  ' Locate a row by its cell value
  ColumnName = "MyColumn"
  ColumnValue = "MyValue"
  RowIndex = FindRow (Grid, ColumnName, ColumnValue, 0)

  ' Check if the row has child data
  Set ChildLevel = Grid.wChildLevel (RowIndex)
  If Not (ChildLevel Is Nothing) Then
    ' Post the number of rows in child views to the log
    For ViewIdx = 0 To ChildLevel.wViewCount-1
      Log.Message (ChildLevel.wView(ViewIdx) & ": " & ChildLevel.wRowCount(ViewIdx) & " rows.")
    Next
  End If
End Sub

Function FindRow (Level, ColumnId, Value, ViewId)
  Dim i
  ' Iterate through the rows
  For i = 0 To Level.wRowCount(ViewId)-1
    ' Check the cell value in the specified column
    If Level.wValue(i, ColumnId, ViewId) = Value Then
      FindRow = i ' Row is found
      Exit Function
    End If
  Next

  FindRow = -1 ' Row is not found
End Function

DelphiScript

function FindRow (Level, ColumnId, Value, ViewId : OleVariant = 0);
var i : OleVariant;
begin
  // Iterate through the rows
  for i := 0 to Level.wRowCount[ViewId]-1 do
    // Check the cell value in the specified column
    if Level.wValue[i, ColumnId, ViewId] = Value then
    begin
      Result := i; // Row is found
      Exit
    end;

  Result := -1; // Row is not found
end;

procedure Main;
var p, Grid, ColumnName, ColumnValue, ChildLevel, RowIndex, ViewIdx : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');

  // Locate a row by its cell value
  ColumnName := 'MyColumn';
  ColumnValue := 'MyValue';
  RowIndex := FindRow (Grid, ColumnName, ColumnValue);

  // Check if the row has child data
  ChildLevel := Grid.wChildLevel[RowIndex];
  if ChildLevel <> nil then
  begin
    // Post the number of rows in child views to the log
    for ViewIdx := 0 to ChildLevel.wViewCount-1 do
      Log.Message (ChildLevel.wView[ViewIdx] + ': ' + aqConvert.VarToStr(ChildLevel.wRowCount[ViewIdx]) + ' rows.');
  end
end;

C++Script, C#Script

function Main ()
{
  var p, Grid, ColumnName, ColumnValue, ChildLevel, RowIndex, ViewIdx;

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

  // Locate a row by its cell value
  ColumnName = "MyColumn";
  ColumnValue = "MyValue";
  RowIndex = FindRow (Grid, ColumnName, ColumnValue);

  // Check if the row has child data
  ChildLevel = Grid["wChildLevel"](RowIndex);
  if (ChildLevel != null)
  {
    // Post the number of rows in child views to the log
    for (ViewIdx=0; ViewIdx<ChildLevel["wViewCount"]; ViewIdx++)
      Log["Message"](ChildLevel["wView"](ViewIdx) + ": " + ChildLevel["wRowCount"](ViewIdx) + " rows.");
  }
}

function FindRow (Level, ColumnId, Value, ViewId)
{
  // If the ViewId parameter is not specified,
  // initialize it with the default value
  if (typeof(ViewId) == "undefined")
    ViewId = 0;

  // Iterate through the rows
  for (var i=0; i<Level["wRowCount"](ViewId); i++)
    // Check the cell value in the specified column
    if (Level["wValue"](i, ColumnId, ViewId) == Value)
      return i; // Row is found

  return -1; // Row is not found
}

Using TcxGrid Internal Methods and Properties

Sometimes you may need to get “native” VCL objects that represent a particular level or view. For example, you may want to perform specific actions or checks using internal methods and properties of the QuantumGrid control.

The TcxGrid object (TcxGrid is the class name of the QuantumGrid control) has two properties that let you quickly access certain views:

  • ActiveView - Returns the view that is associated with the root level.
  • FocusedView - Returns the view that currently has focus and responds to user input.

The code snippet below demonstrates how you can determine the number of rows and columns in the currently focused view:

JavaScript, JScript

var Grid;

// Obtain the grid object
...

Log.Message ("Row count: " + Grid.FocusedView.ViewData.RecordCount);
Log.Message ("Column count: " + Grid.FocusedView.ColumnCount);

Python

# Obtain the grid object
...

Log.Message ("Row count: " + Grid.FocusedView.ViewData.RecordCount)
Log.Message ("Column count: " + Grid.FocusedView.ColumnCount)

VBScript

Dim Grid

' Obtain the grid object
...

Log.Message ("Row count: " & Grid.FocusedView.ViewData.RecordCount)
Log.Message ("Column count: " & Grid.FocusedView.ColumnCount)

DelphiScript

var Grid : OleVariant;
...

// Obtain the grid object
...

Log.Message ('Row count: ' + aqConvert.VarToStr(Grid.FocusedView.ViewData.RecordCount));
Log.Message ('Column count: ' + aqConvert.VarToStr(Grid.FocusedView.ColumnCount));

C++Script, C#Script

var Grid;

// Obtain the grid object
...

Log["Message"]("Row count: " + Grid["FocusedView"]["ViewData"]["RecordCount"]);
Log["Message"]("Column count: " + Grid["FocusedView"]["ColumnCount"]);

If the grid displays hierarchical data, you will need to work with the data displayed in the top-level view as well as in its child views. To obtain a “native” child view object, you need to create a script that performs the following actions:

  • Obtains the object corresponding to the row whose child data you want to get. You can do that using the ViewData.Rows(Index) property of the view that contains this row.
  • Gets the desired child view. For this purpose, you can use the row’s DetailGridViews (Index) property. To get the total number of child views, use the DetailGridViewCount property.

The following example demonstrates how you can use these properties to obtain the child views:

Example

View description

JavaScript, JScript

function Main ()
{
  var p, Grid, ColumnName, ColumnValue, RowIndex, Row, ChildView, i;

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


  // Locate a row by its cell value
  ColumnName = "MyColumn";
  ColumnValue = "MyValue";
  RowIndex = FindRow (Grid, ColumnName, ColumnValue);

  // Get the row object
  Row = Grid.ActiveView.ViewData.Rows (RowIndex);
  // Check if the row has child data
  if (aqObject.IsSupported (Row, "DetailGridViewCount"))
  {
    // Iterate through child views
    for (i = 0; i < Row.DetailGridViewCount; i++)
    {
      // Get a child view by index
      ChildView = Row.DetailGridViews(i);
      // Post the number of rows in a child view to the log
      Log.Message (ChildView.Level.Caption + ": " + ChildView.ViewData.RecordCount + " rows.");
    }
  }
}

Python

def Main ():

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


  # Locate a row by its cell value
  ColumnName = "MyColumn"
  ColumnValue = "MyValue"
  RowIndex = FindRow (Grid, ColumnName, ColumnValue)

  # Get the row object
  Row = Grid.ActiveView.ViewData.Rows (RowIndex)
  # Check if the row has child data
  if (aqObject.IsSupported (Row, "DetailGridViewCount")) :
    # Iterate through child views
    for i in range(0, Row.DetailGridViewCount-1):
      # Get a child view by index
      ChildView = Row.DetailGridViews[i]
      # Post the number of rows in a child view to the log
      Log.Message (ChildView.Level.Caption + ": " + ChildView.ViewData.RecordCount + " rows.")

VBScript

Sub Main
  Dim p, Grid, ColumnName, ColumnValue, RowIndex, Row, ChildView, i

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

  ' Locate a row by its cell value
  ColumnName = "MyColumn"
  ColumnValue = "MyValue"
  RowIndex = FindRow (Grid, ColumnName, ColumnValue, 0)

  ' Get the row object
  Set Row = Grid.ActiveView.ViewData.Rows (RowIndex)
  ' Check if the row has child data
  If aqObject.IsSupported (Row, "DetailGridViewCount") Then 
    ' Iterate through child views
    For i = 0 to Row.DetailGridViewCount-1
      ' Get a child view by index
      Set ChildView = Row.DetailGridViews(i)
      ' Post the number of rows in a child view to the log
      Log.Message (ChildView.Level.Caption & ": " & ChildView.ViewData.RecordCount & " rows.")
    Next
  End If
End Sub

DelphiScript

procedure Main;
var p, Grid, ColumnName, ColumnValue, RowIndex, Row, ChildView, i : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');

  // Locate a row by its cell value
  ColumnName := 'MyColumn';
  ColumnValue := 'MyValue';
  RowIndex := FindRow (Grid, ColumnName, ColumnValue);

  // Get the row object
  Row := Grid.ActiveView.ViewData.Rows (RowIndex);
  // Check if the row has child data
  if aqObject.IsSupported (Row, 'DetailGridViewCount') then 
  begin
    // Iterate through child views
    for i := 0 to Row.DetailGridViewCount-1 do
    begin
      // Get a child view by index
      ChildView := Row.DetailGridViews(i);
      // Post the number of rows in a child view to the log
      Log.Message (ChildView.Level.Caption + ': ' + aqConvert.VarToStr(ChildView.ViewData.RecordCount) + ' rows.');
    end
  end
end;

C++Script, C#Script

function Main ()
{
  var p, Grid, ColumnName, ColumnValue, RowIndex, Row, ChildView, i;

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


  // Locate a row by its cell value
  ColumnName = "MyColumn";
  ColumnValue = "MyValue";
  RowIndex = FindRow (Grid, ColumnName, ColumnValue);

  // Get the row object
  Row = Grid["ActiveView"]["ViewData"]["Rows"](RowIndex);
  // Check if the row has child data
  if (aqObject["IsSupported"](Row, "DetailGridViewCount"))
  {
    // Iterate through child views
    for (i = 0; i < Row["DetailGridViewCount"]; i++)
    {
      // Get a child view by index
      ChildView = Row["DetailGridViews"](i);
      // Post the number of rows in a child view to the log
      Log["Message"](ChildView["Level"]["Caption"] + ": " + ChildView["ViewData"]["RecordCount"] + " rows.");
    }
  }
}

See Also

Working With Developer Express QuantumGrid
Obtaining and Setting Cell Values in Developer Express QuantumGrid
wChildLevel Property (Specific to Developer Express QuantumGrid Controls)
wView Property (Specific to Developer Express QuantumGrid Controls)
wViewCount Property (Specific to Developer Express QuantumGrid Controls)

Highlight search results