When testing applications that use the QuantumGrid control by Developer Express, you may need to know what row and cell is currently focused. To do this, create a script that will perform the following actions:
-
Obtain the currently focused view (the QuantumGrid control can display data in several levels. Each level has an associated view object that defines what data the level displays and how it displays them. See also Getting Views in Developer Express QuantumGrid). To access the focused row, you need to know what view is focused. To do this, use the
FocusedView
property of the grid object. It returns the view object that corresponds to the focused grid view. -
Use the
ViewData.Controller.FocusedRowIndex
property of the view object to get the index of the focused row among other rows. -
To obtain the index of the focused column, use the view object’s
ViewData.Controller.FocusedColumnIndex
property.
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 |
The following code demonstrates how you can use the described properties to obtain the value of the focused cell. For more information on getting the cell values, see Obtaining and Setting Cell Values in Developer Express QuantumGrid.
JavaScript, JScript
function Main ()
{
var p, Grid, View, RowIndex, ColIndex;
// Obtain the grid object
p = Sys.Process("MySampleApp");
Grid = p.VCLObject("FormName").VCLObject("GridName");
// Get the focused view
View = Grid.FocusedView;
// Get the indexes of the focused row and column
RowIndex = View.ViewData.Controller.FocusedRowIndex;
ColIndex = View.ViewData.Controller.FocusedColumnIndex;
// Post information about the focused cell to the log
Log.Message ("Focused row: " + RowIndex);
Log.Message ("Focused column: " + ColIndex);
Log.Message ("Focused column: " + View.Columns(ColIndex).Caption);
Log.Message ("Focused cell's text: " + View.ViewData.Rows(RowIndex).DisplayTexts(ColIndex));
}
Python
def Main ():
# Obtain the grid object
p = Sys.Process("MySampleApp")
Grid = p.VCLObject("FormName").VCLObject("GridName")
# Get the focused view
View = Grid.FocusedView
# Get the indexes of the focused row and column
RowIndex = View.ViewData.Controller.FocusedRowIndex
ColIndex = View.ViewData.Controller.FocusedColumnIndex
# Post information about the focused cell to the log
Log.Message ("Focused row: " + RowIndex)
Log.Message ("Focused column: " + ColIndex)
Log.Message ("Focused column: " + View.Columns(ColIndex).Caption)
Log.Message ("Focused cell's text: " + View.ViewData.Rows(RowIndex).DisplayTexts(ColIndex))
VBScript
Sub Main
Dim p, Grid, View, RowIndex, ColIndex
' Obtain the grid object
Set p = Sys.Process("MySampleApp")
Set Grid = p.VCLObject("FormName").VCLObject("GridName")
' Get the focused view
Set View = Grid.FocusedView
' Get the indexes of the focused row and column
RowIndex = View.ViewData.Controller.FocusedRowIndex
ColIndex = View.ViewData.Controller.FocusedColumnIndex
' Post information about the focused cell to the log
Log.Message ("Focused row: " & RowIndex)
Log.Message ("Focused column: " & ColIndex)
Log.Message ("Focused column: " & View.Columns(ColIndex).Caption)
Log.Message ("Focused cell's text: " & View.ViewData.Rows(RowIndex).DisplayTexts(ColIndex))
End Sub
DelphiScript
procedure Main;
var p, Grid, View, RowIndex, ColIndex : OleVariant;
begin
// Obtain the grid object
p := Sys.Process('MySampleApp');
Grid := p.VCLObject('FormName').VCLObject('GridName');
// Get the focused view
View := Grid.FocusedView;
// Get the indexes of the focused row and column
RowIndex := View.ViewData.Controller.FocusedRowIndex;
ColIndex := View.ViewData.Controller.FocusedColumnIndex;
// Post information about the focused cell to the log
Log.Message ('Focused row: ' + aqConvert.VarToStr(RowIndex));
Log.Message ('Focused column: ' + aqConvert.VarToStr(ColIndex));
Log.Message ('Focused column: ' + View.Columns[ColIndex].Caption);
Log.Message ('Focused cell''s text: ' + View.ViewData.Rows[RowIndex].DisplayTexts[ColIndex]);
end;
C++Script, C#Script
function Main ()
{
var p, Grid, View, RowIndex, ColIndex;
// Obtain the grid object
p = Sys["Process"]("MySampleApp");
Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");
// Get the focused view
View = Grid["FocusedView"];
// Get the indexes of the focused row and column
RowIndex = View["ViewData"]["Controller"]["FocusedRowIndex"];
ColIndex = View["ViewData"]["Controller"]["FocusedColumnIndex"];
// Post information about the focused cell to the log
Log["Message"]("Focused row: " + RowIndex);
Log["Message"]("Focused column: " + ColIndex);
Log["Message"]("Focused column: " + View["Columns"](ColIndex)["Caption"]);
Log["Message"]("Focused cell's text: " + View["ViewData"]["Rows"](RowIndex)["DisplayTexts"](ColIndex));
}
See Also
Working With Developer Express QuantumGrid
Obtaining and Setting Cell Values in Developer Express QuantumGrid
Selecting Cells in Developer Express QuantumGrid