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:
When testing Developer Express QuantumGrid controls, use specific methods and properties of the corresponding |
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
JavaScript
function Main ()
{
var p, Grid, ChildLevel, RowIndex;
// Obtain the grid object
p = Sys.Process("Project1");
Grid = p.VCLObject("Form1").VCLObject("cxGrid1");
// Locate a row by its cell value
RowIndex = FindRow (Grid, "Product ID", 2674);
// 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, ChildLevel, RowIndex, ViewIdx;
// Obtain the grid object
p = Sys.Process("Project1");
Grid = p.VCLObject("Form1").VCLObject("cxGrid1");
// Locate a row by its cell value
RowIndex = FindRow (Grid, "Product ID", 2674);
// 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("Project1")
Grid = p.VCLObject("Form1").VCLObject("cxGrid1")
# Locate a row by its cell value
RowIndex = FindRow (Grid, "Product ID", 2674)
# 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, ChildLevel, RowIndex, ViewIdx
' Obtain the grid object
Set p = Sys.Process("Project1")
Set Grid = p.VCLObject("Form1").VCLObject("cxGrid1")
' Locate a row by its cell value
RowIndex = FindRow (Grid, "Product ID", 2674, 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, ChildLevel, RowIndex, ViewIdx : OleVariant;
begin
// Obtain the grid object
p := Sys.Process('Project1');
Grid := p.VCLObject('Form1').VCLObject('cxGrid1');
// Locate a row by its cell value
RowIndex := FindRow (Grid, 'Product ID', 2674);
// 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, ChildLevel, RowIndex, ViewIdx;
// Obtain the grid object
p = Sys["Process"]("Project1");
Grid = p["VCLObject"]("Form1")["VCLObject"]("cxGrid1");
// Locate a row by its cell value
RowIndex = FindRow (Grid, "Product ID", 2674);
// 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 theDetailGridViewCount
property.
The following example demonstrates how you can use these properties to obtain the child views:
Example
JavaScript, JScript
function Main ()
{
var p, Grid, RowIndex, Row, ChildView, i;
// Obtain the grid object
p = Sys.Process("Project1");
Grid = p.VCLObject("Form1").VCLObject("cxGrid1");
// Locate a row by its cell value
RowIndex = FindRow (Grid, "Product ID", "2674");
// 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("Project1")
Grid = p.VCLObject("Form1").VCLObject("cxGrid1")
# Locate a row by its cell value
RowIndex = FindRow (Grid, "Product ID", "2674")
# 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, RowIndex, Row, ChildView, i
' Obtain the grid object
Set p = Sys.Process("Project1")
Set Grid = p.VCLObject("Form1").VCLObject("cxGrid1")
' Locate a row by its cell value
RowIndex = FindRow (Grid, "Product ID", "2674", 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, RowIndex, Row, ChildView, i : OleVariant;
begin
// Obtain the grid object
p := Sys.Process('Project1');
Grid := p.VCLObject('Form1').VCLObject('cxGrid1');
// Locate a row by its cell value
RowIndex := FindRow (Grid, 'Product ID', '2674');
// 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, RowIndex, Row, ChildView, i;
// Obtain the grid object
p = Sys["Process"]("Project1");
Grid = p["VCLObject"]("Form1")["VCLObject"]("cxGrid1");
// Locate a row by its cell value
RowIndex = FindRow (Grid, "Product ID", "2674");
// 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)