Getting Focused Row, Column and Cell in Developer Express QuantumGrid

Applies to TestComplete 15.69, last modified on November 13, 2024

About

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.

Requirements

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.

Example

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;

  // Make sure, your application is compiled with debug information
  // 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 cell's text: " + View.ViewData.Rows(RowIndex).DisplayTexts(ColIndex));
}

Python

def Main ():
  # Make sure, your application is compiled with debug information
  # 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 cell's text: " + View.ViewData.Rows(RowIndex).DisplayTexts(ColIndex))

VBScript

Sub Main
  Dim p, Grid, View, RowIndex, ColIndex

  ' Make sure, your application is compiled with debug information
  ' 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 cell's text: " & View.ViewData.Rows(RowIndex).DisplayTexts(ColIndex))
End Sub

DelphiScript

procedure Main;
var p, Grid, View, RowIndex, ColIndex : OleVariant;
begin
  // Make sure, your application is compiled with debug information
  // 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 cell''s text: ' + View.ViewData.Rows[RowIndex].DisplayTexts[ColIndex]);
end;

C++Script, C#Script

function Main ()
{
  var p, Grid, View, RowIndex, ColIndex;

  // Make sure, your application is compiled with debug information
  // 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 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

Highlight search results