Selecting Multiple Rows in Syncfusion GridDataBoundGrid

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

It's possible to select multiple rows in the GridDataBoundGrid control at one time. You can perform various operations over the selected rows, for example, copy their data to the clipboard, delete them, and so on. Note that before selecting grid rows, you need to locate them within the grid. For example, you can search for the desired rows by the cells' text values.

The following sections describe the approaches that can be used to select multiple rows in the GridDataBoundGrid control:

To perform these actions, TestComplete should have access to internal objects, properties and methods of the GridDataBoundGrid control. For this purpose, the .NET Application Support plugin must be installed and enabled.

When testing Syncfusion GridDataBoundGrid controls, use specific methods and properties of the corresponding SyncfusionEssGrid 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 GridDataBoundGrid 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.

General Notes

It is possible to select multiple rows in the GridDataBoundGrid control from TestComplete scripts in two ways:

  • By selecting the desired rows with mouse or keyboard while holding Ctrl or Shift.
  • By using internal properties and methods of the GridDataBoundGrid control.

The first approach simulates user interaction with the grid control. It implies selecting rows by clicking on their headers. However, this approach depends on several grid options: it requires the grid control to be configured so that the row headers are displayed and multiple row selection by the mouse is enabled (see below).

The approach that uses internal properties methods of the GridDataBoundGrid object is simpler and more stable. It lets you select multiple grid rows even if this is impossible to do using user interaction with the grid control.

In this topic, we will use both approaches. In your scripts, you can use the approach that suits your needs the best.

Option That Affects Row Selection in GridDataBoundGrid

The GridDataBoundGrid control has the AllowSelection property that specifies how the users can select grid rows, columns and cells. This property holds a set of flags that enable various aspects of the selection behavior. The table below lists flags that affect multiple row selection:

Flag Description
“Row” (1) It is possible to select an entire row by clicking on its header.
“Multiple” (16) It is possible to select multiple rows by Ctrl-clicks on row headers.
“Shift” (32) It is possible to select row ranges by Shift-clicks on row headers.

In scripts, you can check whether the AllowSelection property contains these flags by doing any of the following:

  • Search for the string representation of the flag value in the string returned by the AllowSelection.OleValue property (see Working With Strings to learn how you can do this).

  • Compare the AllowSelection.value___ value with the flag value (numeric) using the bitwise logical OR operator.

Simulating Selections With Mouse

The users can select rows in the GridDataBoundGrid control by clicking on row headers. Multiple row selections are possible by pressing Ctrl or Shift while selecting the rows. Holding Ctrl while selecting the row adds it to the current selection, and holding Shift extends selection to the selected row.

You can simulate Ctrl- and Shift-clicks on row headers using the Click action applied to the grid control. This action takes the coordinates of the point to click, and the optional Shift parameter that specifies the key to be “pressed” when performing the click. To select several rows, you can use successive Click calls with the desired row header coordinates and the needed Shift parameter values.

To determine coordinates of a particular row header cell, you can use the following code:

rect = GridObj.RangeInfoToRectangle ( GridObj.GridCellsRange.Cell ( RowIndex, 0 ) )

GridObj is the GridDataBoundGrid object and RowIndex is the zero-based absolute index of the desired row. For more information on identifying GridDataBoundGrid rows and columns, see Accessing Rows, Columns and Cells in Syncfusion GridDataBoundGrid. The resulting rect object is a .NET System.Drawing.Rectangle object that holds the grid-relative coordinates of the row header cell.

Note however, that the row headers may not be displayed, so it may be impossible to click on them. You can check whether the row headers are visible by examining the GridObj.Model.Cols.Hidden.Item(0) value: if it is False, then row headers are visible, otherwise they are hidden.

Below is an example that illustrates how you can simulate Ctrl- and Shift-clicks on row headers in the GridDataBoundGrid control to select multiple rows.

Example

View description

JavaScript, JScript

function Main ()
{
  var p, Grid, RowIndexes;

  // Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1");

  // Select rows 10-20
  SelectRange (Grid, 10, 20);
  aqUtils.Delay (1000);

  // Select the specified rows
  RowIndexes = new Array (10, 12, 15, 17, 23);
  SelectRows (Grid, RowIndexes);
}

function SelectRange (Grid, StartRowIndex, EndRowIndex)
{
  // Check if row headers are displayed
  if (Grid.Model.Cols.Hidden.Item(0))
    Log.Error ("Cannot click on row headers because row headers are hidden.")
  else
  {
    // Check if row selection is possible
    if (((Grid.AllowSelection.value__ & 1) == 0) ||  // Check if AllowSelection contains the Rows flag
        ((Grid.AllowSelection.value__ & 32) == 0))   // Check if AllowSelection contains the Shift flag
      Log.Error("Grid does not support selection of row ranges.")
    else
    {
      ClickRowHeader (Grid, StartRowIndex, skNoShift);
      ClickRowHeader (Grid, EndRowIndex, skShift);
    }
  }
}

function SelectRows (Grid, RowIndexes)
{
  // Check if row headers are displayed
  if (Grid.Model.Cols.Hidden.Item(0))
    Log.Error ("Cannot click on row headers because row headers are hidden.")
  else
  {
    // Check if row selection is possible
    if (((Grid.AllowSelection.value__ & 1) == 0) ||  // Check if AllowSelection contains the Rows flag
        ((Grid.AllowSelection.value__ & 16) == 0))   // Check if AllowSelection contains the Multiple flag
      Log.Error("Grid does not support selection of multiple rows.")
    else
    {
      ClickRowHeader (Grid, RowIndexes[0], skNoShift);
      for (var i=1; i<RowIndexes.length; i++)
        ClickRowHeader (Grid, RowIndexes[i], skCtrl);
    }
  }
}

function ClickRowHeader (Grid, RowIndex, Shift)
{
  var rect;

  // Check if row headers are displayed
  if (! Grid.Model.Cols.Hidden.Item(0))
  {
    // Make row visible
    Grid.ScrollCellInView_3(RowIndex, 0);

    // Get the row header coordinates
    rect = Grid.RangeInfoToRectangle (Grid.GridCellsRange.Cell(RowIndex, 0));

    Grid.Click (rect.X + rect.Width/2, rect.Y + rect.Height/2, Shift);
  }
  else
    Log.Error ("Cannot click on row header because row headers are hidden.");
}

Python

def Main ():

  # Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  # Select rows 10-20
  SelectRange (Grid, 10, 20)
  aqUtils.Delay (1000)

  # Select the specified rows
  RowIndexes = list(10, 12, 15, 17, 23)
  SelectRows (Grid, RowIndexes)

def SelectRange (Grid, StartRowIndex, EndRowIndex):
  # Check if row headers are displayed
  if (Grid.Model.Cols.Hidden.Item[0]):
    Log.Error ("Cannot click on row headers because row headers are hidden.")
  else:
    # Check if row selection is possible
    if (((Grid.AllowSelection.value__ & 1) == 0) or  # Check if AllowSelection contains the Rows flag
        ((Grid.AllowSelection.value__ & 32) == 0)):   # Check if AllowSelection contains the Shift flag
      Log.Error("Grid does not support selection of row ranges.")
    else:
      ClickRowHeader (Grid, StartRowIndex, skNoShift)
      ClickRowHeader (Grid, EndRowIndex, skShift)

def SelectRows (Grid, RowIndexes):
  # Check if row headers are displayed
  if (Grid.Model.Cols.Hidden.Item[0]):
    Log.Error ("Cannot click on row headers because row headers are hidden.")
  else:
    # Check if row selection is possible
    if (((Grid.AllowSelection.value__ & 1) == 0) or  # Check if AllowSelection contains the Rows flag
        ((Grid.AllowSelection.value__ & 16) == 0)):   # Check if AllowSelection contains the Multiple flag
      Log.Error("Grid does not support selection of multiple rows.")
    else:
      ClickRowHeader (Grid, RowIndexes[0], skNoShift)
      for i in range(1, RowIndexes.length-1):
        ClickRowHeader (Grid, RowIndexes[i], skCtrl)

def ClickRowHeader (Grid, RowIndex, Shift):

  # Check if row headers are displayed
  if not Grid.Model.Cols.Hidden.Item[0]:
    # Make row visible
    Grid.ScrollCellInView_3(RowIndex, 0)

    # Get the row header coordinates
    rect = Grid.RangeInfoToRectangle (Grid.GridCellsRange.Cell[RowIndex, 0])

    Grid.Click (rect.X + rect.Width/2, rect.Y + rect.Height/2, Shift)
  else:
    Log.Error ("Cannot click on row header because row headers are hidden.")

VBScript

Sub Main
  Dim p, Grid, RowIndexes

  ' Obtain the application process and the grid object
  Set p = Sys.Process ("DataBoundSortByDisplayMember")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  ' Select rows 10-20
  Call SelectRange (Grid, 10, 20)
  Call aqUtils.Delay (1000)

  ' Select the specified rows
  RowIndexes = Array (10, 12, 15, 17, 23)
  Call SelectRows (Grid, RowIndexes)
End Sub

Sub SelectRange (Grid, StartRowIndex, EndRowIndex)
  ' Check if row headers are displayed
  If Grid.Model.Cols.Hidden.Item(0) Then
    Call Log.Error ("Cannot click on row headers because row headers are hidden.")
  Else
    ' Check if row selection is possible, i.e. if AllowSelection contains the Rows and Shift flags
    If ((Grid.AllowSelection.value__ And 1) = 0) Or ((Grid.AllowSelection.value__ And 32) = 0) Then
      Call Log.Error ("Grid does not support selection of row ranges.")
    Else
      Call ClickRowHeader (Grid, StartRowIndex, skNoShift)
      Call ClickRowHeader (Grid, EndRowIndex, skShift)
    End If
  End If
End Sub

Sub SelectRows (Grid, RowIndexes)
  ' Check if row headers are displayed
  If Grid.Model.Cols.Hidden.Item(0) Then
    Log.Error ("Cannot click on row headers because row headers are hidden.")
  Else
    ' Check if row selection is possible, i.e. if AllowSelection contains the Rows and Multiple flags
    If (((Grid.AllowSelection.value__ And 1) = 0) Or ((Grid.AllowSelection.value__ And 16) = 0)) Then
      Log.Error("Grid does not support selection of multiple rows.")
    Else
      Call ClickRowHeader (Grid, RowIndexes(0), skNoShift)
      For i=1 To UBound(RowIndexes)
        Call ClickRowHeader (Grid, RowIndexes(i), skCtrl)
      Next
    End If
  End If
End Sub

Sub ClickRowHeader (Grid, RowIndex, Shift)
  Dim rect

  ' Check if row headers are displayed
  If Not Grid.Model.Cols.Hidden.Item(0) Then
    ' Make row visible
    Call Grid.ScrollCellInView_3(RowIndex, 0)

    ' Get the row header coordinates
    Set rect = Grid.RangeInfoToRectangle (Grid.GridCellsRange.Cell(RowIndex, 0))

    Call Grid.Click (rect.X + rect.Width/2, rect.Y + rect.Height/2, Shift)
  Else
    Call Log.Error ("Cannot click on row header because row headers are hidden.")
  End If
End Sub

DelphiScript

procedure SelectRange (Grid, StartRowIndex, EndRowIndex); forward;
procedure SelectRows (Grid, RowIndexes); forward;
procedure ClickRowHeader (Grid, RowIndex, Shift); forward;

procedure Main;
var p, Grid, RowIndexes : OleVariant;
begin
  // Obtain the application process and the grid object
  p := Sys.Process ('DataBoundSortByDisplayMember');
  Grid := p.WinFormsObject('Form1').WinFormsObject('gridDataBoundGrid1');

  // Select rows 10-20
  SelectRange (Grid, 10, 20);
  aqUtils.Delay (1000);

  // Select the specified rows
  RowIndexes := CreateVariantArray (0, 4);
  RowIndexes[0] := 10;    RowIndexes[1] := 12;
  RowIndexes[2] := 15;    RowIndexes[3] := 17;
  RowIndexes[4] := 23;
  SelectRows (Grid, RowIndexes);
end;

procedure SelectRange (Grid, StartRowIndex, EndRowIndex);
begin;
  // Check if row headers are displayed
  if Grid.Model.Cols.Hidden.Item(0) then
    Log.Error ('Cannot click on row headers because row headers are hidden.')
  else
  begin
    // Check if row selection is possible
    if (((Grid.AllowSelection.value__ and 1) = 0) or     // Check if AllowSelection contains the Rows flag
        ((Grid.AllowSelection.value__ and 32) = 0)) then // Check if AllowSelection contains the Shift flag
      Log.Error ('Grid does not support selection of row ranges.')
    else
    begin
      ClickRowHeader (Grid, StartRowIndex, skNoShift);
      ClickRowHeader (Grid, EndRowIndex, skShift);
    end
  end
end;

procedure SelectRows (Grid, RowIndexes);
var i : OleVariant;
begin
  // Check if row headers are displayed
  if Grid.Model.Cols.Hidden.Item(0) then
    Log.Error ('Cannot click on row headers because row headers are hidden.')
  else
  begin
    // Check if row selection is possible
    if (((Grid.AllowSelection.value__ and 1) = 0) or     // Check if AllowSelection contains the Rows flag
        ((Grid.AllowSelection.value__ and 16) = 0)) then // Check if AllowSelection contains the Multiple flag
      Log.Error('Grid does not support selection of multiple rows.')
    else
    begin
      ClickRowHeader (Grid, RowIndexes[0], skNoShift);
      for i:=1 to VarArrayHighBound(RowIndexes, 1) do
        ClickRowHeader (Grid, RowIndexes[i], skCtrl);
    end
  end
end;

procedure ClickRowHeader (Grid, RowIndex, Shift);
var rect : OleVariant;
begin
  // Check if row headers are displayed
  if not Grid.Model.Cols.Hidden.Item(0) then
  begin
    // Make row visible
    Grid.ScrollCellInView_3(RowIndex, 0);

    // Get the row header coordinates
    rect := Grid.RangeInfoToRectangle (Grid.GridCellsRange.Cell(RowIndex, 0));

    Grid.Click (rect.X + rect.Width/2, rect.Y + rect.Height/2, Shift);
  end
  else
    Log.Error ('Cannot click on row header because row headers are hidden.');
end;

C++Script, C#Script

function Main ()
{
  var p, Grid, RowIndexes;

  p = Sys["Process"]("samplebrowser");
  FormMain = p["WinFormsObject"]("FormMain");
  // Select the "DataBoundSortByDisplayMember" demo
  SamplesTree = FormMain["WinFormsObject"]("pnlTree")["WinFormsObject"]("xpTaskPane1")["WinFormsObject"]("wizardContainer1")["WinFormsObject"]("treeViewMain");
  SamplesTree["ExpandItem"]("|Essential Studio Samples|Grid samples|Samples|DataBound");
  SamplesTree["ClickItem"]("|Essential Studio Samples|Grid samples|Samples|DataBound|DataBoundSortByDisplayMember");
  RunSampleBtn = FormMain["WinFormsObject"]("pnlHtmlView")["WinFormsObject"]("HTMLUIControl", "")["Document"]["GetElementByUserId"]("runsample");
  FormMain["WinFormsObject"]("pnlHtmlView")["WinFormsObject"]("HTMLUIControl", "")["Click"](RunSampleBtn["X"] + RunSampleBtn["Width"]/2, RunSampleBtn["Y"] + RunSampleBtn["Height"]/2);

  // Obtain the application process and the grid object
  p = Sys["WaitProcess"]("DataBoundSortByDisplayMember", 15000);
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridDataBoundGrid1");

  // Select rows 10-20
  SelectRange (Grid, 10, 20);
  aqUtils["Delay"] (1000);

  // Select the specified rows
  RowIndexes = new Array (10, 12, 15, 17, 23);
  SelectRows (Grid, RowIndexes);
}

function SelectRange (Grid, StartRowIndex, EndRowIndex)
{
  // Check if row headers are displayed
  if (Grid["Model"]["Cols"]["Hidden"]["Item"](0))
    Log["Error"]("Cannot click on row headers because row headers are hidden.")
  else
  {
    // Check if row selection is possible
    if (((Grid["AllowSelection"]["value__"] & 1) == 0) ||  // Check if AllowSelection contains the Rows flag
        ((Grid["AllowSelection"]["value__"] & 32) == 0))   // Check if AllowSelection contains the Shift flag
      Log["Error"]("Grid does not support selection of row ranges.")
    else
    {
      ClickRowHeader (Grid, StartRowIndex, skNoShift);
      ClickRowHeader (Grid, EndRowIndex, skShift);
    }
  }
}

function SelectRows (Grid, RowIndexes)
{
  // Check if row headers are displayed
  if (Grid["Model"]["Cols"]["Hidden"]["Item"](0))
    Log["Error"]("Cannot click on row headers because row headers are hidden.")
  else
  {
    // Check if row selection is possible
    if (((Grid["AllowSelection"]["value__"] & 1) == 0) ||  // Check if AllowSelection contains the Rows flag
        ((Grid["AllowSelection"]["value__"] & 16) == 0))   // Check if AllowSelection contains the Multiple flag
      Log["Error"]("Grid does not support selection of multiple rows.")
    else
    {
      ClickRowHeader (Grid, RowIndexes[0], skNoShift);
      for (var i=1; i<RowIndexes["length"]; i++)
        ClickRowHeader (Grid, RowIndexes[i], skCtrl);
    }
  }
}

function ClickRowHeader (Grid, RowIndex, Shift)
{
  var rect;

  // Check if row headers are displayed
  if (! Grid["Model"]["Cols"]["Hidden"]["Item"](0))
  {
    // Make row visible
    Grid["ScrollCellInView_3"](RowIndex, 0);

    // Get the row header coordinates
    rect = Grid["RangeInfoToRectangle"](Grid["GridCellsRange"]["Cell"](RowIndex, 0));

    Grid["Click"](rect["X"] + rect["Width"]/2, rect["Y"] + rect["Height"]/2, Shift);
  }
  else
    Log["Error"]("Cannot click on row header because row headers are hidden.");
}

Using the GridDataBoundGrid.Selections Property

The GridDataBoundGrid control has the Selections property that lets you manage the rows, columns and cells selected in the grid. Using methods of the GridModelSelections object returned by the GridDataBoundGrid.Selections property, you can select or unselect the desired grid elements. The following table list some methods that you can use to change the grid selection. For more information on using the GridModelSelections object, please refer to the Syncfusion Essential Grid documentation.

Method Description
GridObj.Selections.Add(GridRangeInfoObj) Adds the specified range of grid elements to the selection.
GridObj.Selections.Remove(GridRangeInfoObj) Unselects the specified range of grid elements.
GridObj.Selections.SelectRange(GridRangeInfoObj, Select) Adds or removes the specified range of grid elements from the selection. The Select parameter specifies if the range should be selected (True) or unselected (False).
GridObj.Selections.Clear() Unselects all selected rows, column and cells in the grid.

As you can see, all of these methods work with GridRangeInfo objects that represent the range of grid elements. You can create an instance of this object using the following instructions:

  • GridObj.GridCellsRange.Row (RowIndex) - Creates a GridRangeInfo object corresponding to the row with the specified absolute index.
  • GridObj.GridCellsRange.Rows (StartRowIndex, EndRowIndex) - Creates a GridRangeInfo object corresponding to the rows in a specified range.

The following example demonstrates how you can use the GridDataBoundGrid.Selections property in scripts. Note that using the GridDataBoundGrid.Selections property, it is possible to select multiple rows even if the grid’s AllowSelection property does not allow it. However, in this example we check the AllowSelection property before selecting rows, and if the row selection is disabled we report an error and do not perform the row selection.

Example

View description

JavaScript, JScript

function Main ()
{
  var p, Grid, RowIndexes;

  // Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1");

  // Select rows 10-20
  SelectRange (Grid, 10, 20);
  aqUtils.Delay (1000);

  // Clear selection
  ClearSelection (Grid);
  aqUtils.Delay (1000);

  // Select multiple rows
  RowIndexes = new Array (10, 12, 15, 17, 23);
  SelectRows (Grid, RowIndexes);
}

function SelectRange (Grid, StartRowIndex, EndRowIndex)
{
  // Check if the grid supports row selection
  // (i.e. if AllowSelection contains the Rows flag)
  if ((Grid.AllowSelection.value__ & 1) == 0)
    Log.Error ("Grid does not support row selection.")
  else
  {
    // Clear the previous selection
    Grid.Selections.Clear();
    // Selects the specified range of rows
    Grid.Selections.Add (Grid.GridCellsRange.Rows(StartRowIndex, EndRowIndex));
  }
}

function SelectRows (Grid, RowIndexes)
{
  // Check if the grid supports row selection
  // (i.e. if AllowSelection contains the Rows flag)
  if ((Grid.AllowSelection.value__ & 1) == 0)
    Log.Error ("Grid does not support row selection.")
  else
  {
    // Clear the previous selection
    Grid.Selections.Clear();
    // Select the specified rows
    for (var i=0; i<RowIndexes.length; i++)
      Grid.Selections.Add (Grid.GridCellsRange.Row(RowIndexes[i]));
  }
}

function ClearSelection (Grid)
{
  Grid.Selections.Clear();
}

Python

def Main ():

  # Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  # Select rows 10-20
  SelectRange (Grid, 10, 20)
  aqUtils.Delay (1000)

  # Clear selection
  ClearSelection (Grid)
  aqUtils.Delay (1000)

  # Select multiple rows
  RowIndexes = list(10, 12, 15, 17, 23)
  SelectRows (Grid, RowIndexes)

def SelectRange (Grid, StartRowIndex, EndRowIndex):
  # Check if the grid supports row selection
  # (i.e. if AllowSelection contains the Rows flag)
  if ((Grid.AllowSelection.value__ & 1) == 0):
    Log.Error ("Grid does not support row selection.")
  else:
    # Clear the previous selection
    Grid.Selections.Clear()
    # Selects the specified range of rows
    Grid.Selections.Add (Grid.GridCellsRange.Rows(StartRowIndex, EndRowIndex))

def SelectRows (Grid, RowIndexes):
  # Check if the grid supports row selection
  # (i.e. if AllowSelection contains the Rows flag)
  if ((Grid.AllowSelection.value__ & 1) == 0):
    Log.Error ("Grid does not support row selection.")
  else:
    # Clear the previous selection
    Grid.Selections.Clear()
    # Select the specified rows
    for i in range(0, RowIndexes.length-1):
      Grid.Selections.Add (Grid.GridCellsRange.Row(RowIndexes[i]))

def ClearSelection (Grid):
  Grid.Selections.Clear()

VBScript

Sub Main
  Dim p, Grid, RowIndexes

  ' Obtain the application process and the grid object
  Set p = Sys.Process ("DataBoundSortByDisplayMember")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  ' Select rows 10-20
  Call SelectRange (Grid, 10, 20)
  Call aqUtils.Delay (1000)

  ' Clear selection
  Call ClearSelection (Grid)
  Call aqUtils.Delay (1000)

  ' Select multiple rows
  RowIndexes = Array (10, 12, 15, 17, 23)
  Call SelectRows (Grid, RowIndexes)
End Sub

Sub SelectRange (Grid, StartRowIndex, EndRowIndex)
  ' Check if row selection is possible
  ' (i.e. if AllowSelection contains the Rows flag)
  If (Grid.AllowSelection.value__ And 1) = 0 Then
    Call Log.Error ("Grid does not support row selection.")
  Else
    ' Clear the selection
    Grid.Selections.Clear
    ' Select the specified range of rows
    Call Grid.Selections.Add (Grid.GridCellsRange.Rows(StartRowIndex, EndRowIndex))
  End If
End Sub

Sub SelectRows (Grid, RowIndexes)
  ' Check if row selection is possible
  ' (i.e. if AllowSelection contains the Rows flag)
  If (Grid.AllowSelection.value__ And 1) = 0 Then
    Log.Error ("Grid does not support row selection.")
  Else
    ' Clear selection
    Grid.Selections.Clear
    ' Select the specified rows
    For i=0 To UBound(RowIndexes)
      Call Grid.Selections.Add (Grid.GridCellsRange.Row(RowIndexes(i)))
    Next
  End If
End Sub

Sub ClearSelection (Grid)
  Grid.Selections.Clear
End Sub

DelphiScript

procedure SelectRange(Grid, StartRowIndex, EndRowIndex); forward;
procedure SelectRows (Grid, RowIndexes); forward;
procedure ClearSelection (Grid); forward;

procedure Main;
var p, Grid, RowIndexes : OleVariant;
begin
  // Obtain the application process and the grid object
  p := Sys.Process ('DataBoundSortByDisplayMember');
  Grid := p.WinFormsObject('Form1').WinFormsObject('gridDataBoundGrid1');

  // Select rows 10-20
  SelectRange(Grid, 10, 20);
  aqUtils.Delay (1000);

  // Clear selection
  ClearSelection (Grid);
  aqUtils.Delay (1000);

  // Select multiple rows
  RowIndexes := CreateVariantArray (0, 4);
  RowIndexes[0] := 10;    RowIndexes[1] := 12;
  RowIndexes[2] := 15;    RowIndexes[3] := 17;
  RowIndexes[4] := 23;
  SelectRows (Grid, RowIndexes);
end;

procedure SelectRange(Grid, StartRowIndex, EndRowIndex);
begin
  // Check if the grid supports row selection
  // (i.e. if AllowSelection contains the Rows flag)
  if (Grid.AllowSelection.value__ and 1) = 0 then
    Log.Error ('Grid does not support row selection.')
  else
  begin
    // Clear the previous selection
    Grid.Selections.Clear;
    // Selects the specified range of rows
    Grid.Selections.Add (Grid.GridCellsRange.Rows(StartRowIndex, EndRowIndex));
  end
end;

procedure SelectRows (Grid, RowIndexes);
var i : OleVariant;
begin
  // Check if the grid supports row selection
  // (i.e. if AllowSelection contains the Rows flag)
  if (Grid.AllowSelection.value__ and 1) = 0 then
    Log.Error ('Grid does not support row selection.')
  else
  begin
    // Clear the previous selection
    Grid.Selections.Clear;
    // Select the specified rows
    for i:=0 to VarArrayHighBound(RowIndexes, 1) do
      Grid.Selections.Add (Grid.GridCellsRange.Row(RowIndexes[i]));
  end;
end;

procedure ClearSelection (Grid);
begin
  Grid.Selections.Clear;
end;

C++Script, C#Script

function Main ()
{
  var p, Grid, RowIndexes;

  // Obtain the application process and the grid object
  p = Sys["Process"]("DataBoundSortByDisplayMember");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridDataBoundGrid1");

  // Select rows 10-20
  SelectRange (Grid, 10, 20);
  aqUtils["Delay"] (1000);

  // Clear selection
  ClearSelection (Grid);
  aqUtils["Delay"] (1000);

  // Select multiple rows
  RowIndexes = new Array (10, 12, 15, 17, 23);
  SelectRows (Grid, RowIndexes);
}

function SelectRange (Grid, StartRowIndex, EndRowIndex)
{
  // Check if the grid supports row selection
  // (i.e. if AllowSelection contains the Rows flag)
  if ((Grid["AllowSelection"]["value__"] & 1) == 0)
    Log["Error"]("Grid does not support row selection.")
  else
  {
    // Clear the previous selection
    Grid["Selections"]["Clear"]();
    // Selects the specified range of rows
    Grid["Selections"]["Add"](Grid["GridCellsRange"]["Rows"](StartRowIndex, EndRowIndex));
  }
}

function SelectRows (Grid, RowIndexes)
{
  // Check if the grid supports row selection
  // (i.e. if AllowSelection contains the Rows flag)
  if ((Grid["AllowSelection"]["value__"] & 1) == 0)
    Log["Error"]("Grid does not support row selection.")
  else
  {
    // Clear the previous selection
    Grid["Selections"]["Clear"]();
    // Select the specified rows
    for (var i=0; i<RowIndexes["length"]; i++)
      Grid["Selections"]["Add"](Grid["GridCellsRange"]["Row"](RowIndexes[i]));
  }
}

function ClearSelection (Grid)
{
  Grid["Selections"]["Clear"]();
}

See Also

Working With Syncfusion GridDataBoundGrid
Accessing Rows, Columns and Cells in Syncfusion GridDataBoundGrid
Obtaining Selected Rows in Syncfusion GridDataBoundGrid
Selecting Cells in Syncfusion GridDataBoundGrid
Iterating Through Rows in Syncfusion GridDataBoundGrid

Highlight search results