When working with QuantumGrid controls, you may need to simulate selecting several grid rows and this topic gives examples of how you can do this. For information on how to get values of the selected rows, see Obtaining Selected Rows in Developer Express QuantumGrid.
![]()  | 
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   | 
General Notes
QuantumGrid can display data in several levels. What data is displayed on a level and how they are displays is specified by view objects.
Multiple selection is possible only if the view object’s OptionsSelection.MultiSelect property is set to True. If you are not sure whether the tested grid supports multi-selection, ask the application developer about this. You can also check this yourself by selecting several records with Ctrl- or Shift-click.
Note that before selecting the rows, you need to locate the desired rows in the grid. For example, you can search for the desired rows using methods described in Searching for Records in Developer Express QuantumGrid.
| Note: | When writing the code that will locate the desired rows, do not use the approaches that simulates keystrokes over the grid window, since pressing a key over the grid window removes the selection from the selected rows. | 
You can select multiple grid rows in the following ways:
- By simulating Ctrl- or Shift-clicks over the desired records (Ctrl-click selects one row; Shift-click selects all rows in the range from the currently selected row to the row where the click occurs).
 - By using the internal properties of the TcxGrid object (TcxGrid is the class name of the QuantumGrid control).
 
Simulating Selections With Mouse
Normally, the users can select multiple rows in the QuantumGrid (TcxGrid) control by pressing Ctrl or Shift while selecting the rows. Holding Ctrl while selecting the row will add it to the current selection, and holding Shift will extend selection to the selected row.
To simulate a click on row indicators in a grid’s top-level table, use the ClickRowIndicator action of the DevExpressQuantumGrid object.
For child-level tables, use the ClickRowIndicator action of a DevExpressQuantumGridLevel object corresponding to this level. The parameters of these actions specify the row to be clicked, and also whether the Shift, Ctrl, Alt or combination of these keys should be pressed during the click.
Example
JavaScript
function Main ()
{
  var p, Grid, RowIndexes;
  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  // Select a range or rows
  SelectRange (Grid, 2, 7);
  aqUtils.Delay (500);
  // Select multiple rows
  RowIndexes = new Array (3, 5, 7, 9, 11);
  SelectRows (Grid, RowIndexes);
							}
// Selects a range of rows
function SelectRange (Level, StartRowIndex, EndRowIndex, ViewId)
							{
  // If the View parameter is omitted, initialize it with the default value
  if (strictEqual(ViewId, undefined))
    ViewId = 0;
  // Select the first row of the range
  Level.ClickRowIndicator (StartRowIndex, ViewId);
  // Extend the selection
  Level.ClickRowIndicator (EndRowIndex, ViewId, skShift); 
							}
// Selects the specified rows
function SelectRows (Level, RowIndexes, ViewId)
							{
  // If the View parameter is omitted, initialize it with the default value
  if (strictEqual(ViewId, undefined))
    ViewId = 0;
  // Select the first of the specified rows
  Level.ClickRowIndicator (RowIndexes[0], ViewId);
  // Add other rows to the selection
  for (let i=1; i<RowIndexes.length; i++)
    Level.ClickRowIndicator (RowIndexes[i], ViewId, skCtrl); 
							}
JScript
function Main ()
{
  var p, Grid, RowIndexes;
  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  // Select a range or rows
  SelectRange (Grid, 2, 7);
  aqUtils.Delay (500);
  // Select multiple rows
  RowIndexes = new Array (3, 5, 7, 9, 11);
  SelectRows (Grid, RowIndexes);
							}
// Selects a range of rows
function SelectRange (Level, StartRowIndex, EndRowIndex, ViewId)
							{
  // If the View parameter is omitted, initialize it with the default value
  if (typeof (ViewId) == "undefined")
    ViewId = 0;
  // Select the first row of the range
  Level.ClickRowIndicator (StartRowIndex, ViewId);
  // Extend the selection
  Level.ClickRowIndicator (EndRowIndex, ViewId, skShift); 
							}
// Selects the specified rows
function SelectRows (Level, RowIndexes, ViewId)
							{
  // If the View parameter is omitted, initialize it with the default value
  if (typeof (ViewId) == "undefined")
    ViewId = 0;
  // Select the first of the specified rows
  Level.ClickRowIndicator (RowIndexes[0], ViewId);
  // Add other rows to the selection
  for (var i=1; i<RowIndexes.length; i++)
    Level.ClickRowIndicator (RowIndexes[i], ViewId, skCtrl); 
}
Python
def Main ():
  # Obtain the grid object
  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  # Select a range or rows
  SelectRange (Grid, 2, 7)
  aqUtils.Delay (500)
  # Select multiple rows
  RowIndexes = list(3, 5, 7, 9, 11)
  SelectRows (Grid, RowIndexes)
# Selects a range of rows
def SelectRange (Level, StartRowIndex, EndRowIndex, ViewId):
  # If the View parameter is omitted, initialize it with the default value
  if (typeof (ViewId) == "undefined"):
    ViewId = 0
  # Select the first row of the range
  Level.ClickRowIndicator (StartRowIndex, ViewId)
  # Extend the selection
  Level.ClickRowIndicator (EndRowIndex, ViewId, skShift)
# Selects the specified rows
def SelectRows (Level, RowIndexes, ViewId):
  # If the View parameter is omitted, initialize it with the default value
  if (typeof (ViewId) == "undefined"):
    ViewId = 0
  # Select the first of the specified rows
  Level.ClickRowIndicator (RowIndexes[0], ViewId)
  # Add other rows to the selection
  for i in range(1, RowIndexes.length-1):
    Level.ClickRowIndicator (RowIndexes[i], ViewId, skCtrl)
VBScript
Sub Main
  Dim p, Grid, RowIndexes
  ' Obtain the grid object
  Set p = Sys.Process("MySampleApp")
  Set Grid = p.VCLObject("FormName").VCLObject("GridName")
  ' Select a range or rows
  Call SelectRange (Grid, 2, 7, 0)
  aqUtils.Delay (500)
  ' Select multiple rows
  RowIndexes = Array (3, 5, 7, 9, 11)
  Call SelectRows (Grid, RowIndexes, 0)
End Sub
' Selects a range of rows
Sub SelectRange (Level, StartRowIndex, EndRowIndex, ViewId)
  ' Select the first row of the range
  Call Level.ClickRowIndicator (StartRowIndex, ViewId)
  ' Extend the selection
  Call Level.ClickRowIndicator (EndRowIndex, ViewId, skShift) 
End Sub
' Selects the specified rows
Sub SelectRows (Level, RowIndexes, ViewId)
  Dim i
  ' Select the first of the specified rows
  Call Level.ClickRowIndicator (RowIndexes(0), ViewId)
  ' Add other rows to the selection
  For i = 1 To UBound(RowIndexes)
    Call Level.ClickRowIndicator (RowIndexes(i), ViewId, skCtrl)
  Next 
End Sub
DelphiScript
procedure SelectRange (Level, StartRowIndex, EndRowIndex, ViewId: OleVariant = 0); forward;
procedure SelectRows (Level, RowIndexes, ViewId: OleVariant = 0); forward;
procedure Main;
var p, Grid, RowIndexes : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');
  // Select a range or rows
  SelectRange (Grid, 2, 7);
  aqUtils.Delay (500);
  // Select multiple rows
  RowIndexes := CreateVariantArray (0, 4);
  RowIndexes[0] := 3;  Rowindexes[1] := 5;
  RowIndexes[2] := 7;  Rowindexes[3] := 9;
  RowIndexes[4] := 11;
  SelectRows (Grid, RowIndexes);
end;
// Selects a range of rows
procedure SelectRange (Level, StartRowIndex, EndRowIndex, ViewId: OleVariant = 0);
begin
  // Select the first row of the range
  Level.ClickRowIndicator (StartRowIndex, ViewId);
  // Extend the selection
  Level.ClickRowIndicator (EndRowIndex, ViewId, skShift); 
end;
// Selects the specified rows
procedure SelectRows (Level, RowIndexes, ViewId: OleVariant = 0);
var i : OleVariant;
begin
  // Select the first of the specified rows
  Level.ClickRowIndicator (RowIndexes[0], ViewId);
  // Add other rows to the selection
  for i := 1 to VarArrayHighBound(RowIndexes, 1) do
    Level.ClickRowIndicator (RowIndexes[i], ViewId, skCtrl); 
end;
C++Script, C#Script
function Main ()
{
  var p, Grid, RowIndexes;
  // Obtain the grid object
  p = Sys["Process"]("MySampleApp");
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");
  // Select a range or rows
  SelectRange (Grid, 2, 7);
  aqUtils["Delay"] (500);
  // Select multiple rows
  RowIndexes = new Array (3, 5, 7, 9, 11);
  SelectRows (Grid, RowIndexes);
}
// Selects a range of rows
function SelectRange (Level, StartRowIndex, EndRowIndex, ViewId)
{
  // If the View parameter is omitted, initialize it with the default value
  if (typeof (ViewId) == "undefined")
    ViewId = 0;
  // Select the first row of the range
  Level["ClickRowIndicator"](StartRowIndex, ViewId);
  // Extend the selection
  Level["ClickRowIndicator"](EndRowIndex, ViewId, skShift); 
}
// Selects the specified rows
function SelectRows (Level, RowIndexes, ViewId)
{
  // If the View parameter is omitted, initialize it with the default value
  if (typeof (ViewId) == "undefined")
    ViewId = 0;
  // Select the first of the specified rows
  Level["ClickRowIndicator"](RowIndexes[0], ViewId);
  // Add other rows to the selection
  for (var i=1; i<RowIndexes["length"]; i++)
    Level["ClickRowIndicator"](RowIndexes[i], ViewId, skCtrl); 
}
Using TcxGrid Internal Methods and Properties
You can also select multiple rows in the QuantumGrid (TcxGrid) control using its internal properties and methods:
- To select a range of rows in the grid, you can use the view’s 
DataController.SelectRows (StartRowIndex, EndRowIndex)method. TheDataController.ClearSelectionmethod lets you unselect all rows in the given view. - To mark an individual row as selected, you can assign True to the 
Selectedproperty of the row object (to obtain this object, use theViewData.Rows(RowIndex)property of the view object). Similarly, you can unselect a row by setting itsSelectedproperty to False. 
Example
JavaScript
function Main_SelectMultipleRows_Internal ()
{
  var p, Grid, RowIndexes;
  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  // Select a range or rows
  ClearSelection(Grid, null); // Clear the previous selection
  SelectRange_2 (Grid, null, 2, 7);
  aqUtils.Delay (500);
  // Select multiple rows
  RowIndexes = new Array (3, 5, 7, 9, 11);
  ClearSelection(Grid, null); // Clear the previous selection
  SelectRows_2 (Grid, null, RowIndexes);
							}
// Selects a range of rows
function SelectRange_2 (Grid, View, StartRowIndex, EndRowIndex)
							{
  // Obtain the view object 
  if (strictEqual(View, null))
    View = Grid.ActiveView;
  // Select the specified range of rows
  View.DataController.SelectRows (StartRowIndex, EndRowIndex);
							}
// Selects the specified rows
function SelectRows_2 (Grid, View, RowIndexes)
							{
  // Obtain the view object 
  if (strictEqual(View, null))
    View = Grid.ActiveView;
  for (let i=0; i<RowIndexes.length; i++)
  {
    let Row = View.ViewData.Rows(RowIndexes[i]);
    // Select the row
    Row.Selected = true;
  }
							}
// Unselects all rows
function ClearSelection (Grid, View)
							{
  // Obtain the view object 
  if (strictEqual(View, null))
    View = Grid.ActiveView;
  View.DataController.ClearSelection();
							}
JScript
function Main_SelectMultipleRows_Internal ()
{
  var p, Grid, RowIndexes;
  // Obtain the grid object
  p = Sys.Process("MySampleApp");
  Grid = p.VCLObject("FormName").VCLObject("GridName");
  // Select a range or rows
  ClearSelection(Grid, null); // Clear the previous selection
  SelectRange_2 (Grid, null, 2, 7);
  aqUtils.Delay (500);
  // Select multiple rows
  RowIndexes = new Array (3, 5, 7, 9, 11);
  ClearSelection(Grid, null); // Clear the previous selection
  SelectRows_2 (Grid, null, RowIndexes);
							}
// Selects a range of rows
function SelectRange_2 (Grid, View, StartRowIndex, EndRowIndex)
							{
  // Obtain the view object 
  if (View == null)
    View = Grid.ActiveView;
  // Select the specified range of rows
  View.DataController.SelectRows (StartRowIndex, EndRowIndex);
}
// Selects the specified rows
function SelectRows_2 (Grid, View, RowIndexes)
{
  var Row, i;
  // Obtain the view object 
  if (View == null)
    View = Grid.ActiveView;
  for (i=0; i<RowIndexes.length; i++)
  {
    Row = View.ViewData.Rows(RowIndexes[i]);
    // Select the row
    Row.Selected = true;
  }
}
// Unselects all rows
function ClearSelection (Grid, View)
{
  // Obtain the view object 
  if (View == null)
    View = Grid.ActiveView;
  View.DataController.ClearSelection();
}
Python
def Main_SelectMultipleRows_Internal ():
  # Obtain the grid object
  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  # Select a range or rows
  ClearSelection(Grid, None) # Clear the previous selection
  SelectRange_2 (Grid, None, 2, 7)
  aqUtils.Delay (500)
  # Select multiple rows
  RowIndexes = list(3, 5, 7, 9, 11)
  ClearSelection(Grid, None) # Clear the previous selection
  SelectRows_2 (Grid, None, RowIndexes)
# Selects a range of rows
def SelectRange_2 (Grid, View, StartRowIndex, EndRowIndex):
  # Obtain the view object 
  if (View == None):
    View = Grid.ActiveView
  # Select the specified range of rows
  View.DataController.SelectRows (StartRowIndex, EndRowIndex)
# Selects the specified rows
def SelectRows_2 (Grid, View, RowIndexes):
  # Obtain the view object 
  if (View == None):
    View = Grid.ActiveView
  for i in range(0, RowIndexes.length-1):
    Row = View.ViewData.Rows(RowIndexes[i])
    # Select the row
    Row.Selected = True
# Unselects all rows
def ClearSelection (Grid, View):
  # Obtain the view object 
  if (View == None):
    View = Grid.ActiveView
  View.DataController.ClearSelection()
VBScript
Sub Main
  Dim p, Grid, RowIndexes
  ' Obtain the grid object
  p = Sys.Process("MySampleApp")
  Grid = p.VCLObject("FormName").VCLObject("GridName")
  ' Select a range or rows
  Call ClearSelection (Grid, Nothing) ' Clear the previous selection
  Call SelectRange_2 (Grid, Nothing, 2, 7)
  aqUtils.Delay (500)
  ' Select multiple rows
  RowIndexes = Array (3, 5, 7, 9, 11)
  Call ClearSelection(Grid, Nothing) ' Clear the previous selection
  Call SelectRows_2 (Grid, Nothing, RowIndexes)
End Sub
' Selects a range of rows
Sub SelectRange_2 (Grid, View, StartRowIndex, EndRowIndex)
  ' Obtain the view object 
  If View Is Nothing Then
    Set View = Grid.ActiveView
  End If
  ' Select the specified range of rows
  Call View.DataController.SelectRows (StartRowIndex, EndRowIndex)
End Sub
' Selects the specified rows
Sub SelectRows_2 (Grid, View, RowIndexes)
  Dim Row, i
  ' Obtain the view object 
  If View Is Nothing Then
    Set View = Grid.ActiveView
  End If
  For i = 0 to UBound(RowIndexes)
    Set Row = View.ViewData.Rows(RowIndexes(i))
    ' Select the row
    Row.Selected = True
  Next
End Sub
' Unselects all rows
Sub ClearSelection (Grid, View)
  ' Obtain the view object 
  If View Is Nothing Then
    Set View = Grid.ActiveView
  End If
  View.DataController.ClearSelection
End Sub
DelphiScript
procedure SelectRange_2 (Grid, View, StartRowIndex, EndRowIndex); forward;
procedure SelectRows_2 (Grid, View, RowIndexes); forward;
procedure ClearSelection (Grid, View); forward;
procedure Main;
var p, Grid, RowIndexes : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('MySampleApp');
  Grid := p.VCLObject('FormName').VCLObject('GridName');
  // Select a range or rows
  ClearSelection(Grid, nil); // Clear the previous selection
  SelectRange_2 (Grid, nil, 2, 7);
  // Select multiple rows
  RowIndexes := CreateVariantArray (0, 4);
  RowIndexes[0] := 3;  Rowindexes[1] := 5;
  RowIndexes[2] := 7;  Rowindexes[3] := 9;
  RowIndexes[4] := 11;
  ClearSelection(Grid, nil); // Clear the previous selection
  SelectRows_2 (Grid, nil, RowIndexes);
end;
// Selects a range of rows
procedure SelectRange_2 (Grid, View, StartRowIndex, EndRowIndex);
begin
  // Obtain the view object 
  if View = nil then
    View := Grid.ActiveView;
  // Select the specified range of rows
  View.DataController.SelectRows (StartRowIndex, EndRowIndex);
end;
// Selects the specified rows
procedure SelectRows_2 (Grid, View, RowIndexes);
var Row, i : OleVariant;
begin
  // Obtain the view object 
  if View = nil then
    View := Grid.ActiveView;
  for i := 0 to VarArrayHighBound(RowIndexes, 1) do
  begin
    Row := View.ViewData.Rows(RowIndexes[i]);
    // Select the row
    Row.Selected := true
  end
end;
// Unselects all rows
procedure ClearSelection (Grid, View);
begin
  // Obtain the view object 
  if View = nil then
    View := Grid.ActiveView;
  View.DataController.ClearSelection;
end;
C++Script, C#Script
function Main_SelectMultipleRows_Internal ()
{
  var p, Grid, RowIndexes;
  // Obtain the grid object
  p = Sys["Process"]("MySampleApp");
  Grid = p["VCLObject"]("FormName")["VCLObject"]("GridName");
  // Select a range or rows
  ClearSelection (Grid, null); // Clear the previous selection
  SelectRange_2 (Grid, null, 2, 7);
  aqUtils["Delay"] (500);
  // Select multiple rows
  RowIndexes = new Array (3, 5, 7, 9, 11);
  ClearSelection (Grid, null); // Clear the previous selection
  SelectRows_2 (Grid, null, RowIndexes);
}
// Selects a range of rows
function SelectRange_2 (Grid, View, StartRowIndex, EndRowIndex)
{
  // Obtain the view object 
  if (View == null)
    View = Grid["ActiveView"];
  // Select the specified range of rows
  View["DataController"]["SelectRows"](StartRowIndex, EndRowIndex);
}
// Selects the specified rows
function SelectRows_2 (Grid, View, RowIndexes)
{
  var Row, i;
  // Obtain the view object 
  if (View == null)
    View = Grid["ActiveView"];
  for (i=0; i<RowIndexes["length"]; i++)
  {
    Row = View["ViewData"]["Rows"](RowIndexes[i]);
    // Select the row
    Row["Selected"] = true;
  }
}
// Unselects all rows
function ClearSelection (Grid, View)
{
  // Obtain the view object 
  if (View == null)
    View = Grid["ActiveView"];
  View["DataController"]["ClearSelection"]();
}
See Also
Working With Developer Express QuantumGrid
Obtaining Selected Rows in Developer Express QuantumGrid
Selecting Cells in Developer Express QuantumGrid
ClickRowIndicator Action (Specific to DevExpressQuantumGrid Controls)

General Notes
View description