Selecting Multiple Rows in Developer Express XtraGrid
Test and Monitor | Posted May 25, 2007

It is possible to select multiple rows in Developer Express XtraGrid control. You can then perform various operations over the selected rows, for example, copy their data to the clipboard, delete them, and so on. This article describes two approaches to performing multiple selections: simulating mouse selections and using XtraGrid’s internal methods. Both approaches require access to internal properties, methods and objects of the XtraGrid control. To enable TestComplete to access them, you need to install and enable the .NET Open Application Support plug-in.

Note also, that the multiple selection in a particular grid view is only enabled if the view’s OptionsSelection.MultiSelect is True. If this property if False, only one row can be selected in a view at a time.

Simulating Selections With Mouse

The users can select multiple rows in the XtraGrid control by pressing Ctrl or Shift or both keys while selecting them. The following table lists possible variants:

Action Description
Clicking a row holding no key. Clears the previous selection and selects the clicked row.
Clicking a row holding the Shift key. Clears the previous selection and selects the range of rows between the clicked row and the previously selected ones.
Clicking a row holding the Ctrl key. Selects the clicked row, preserving the previous selection.
Clicking a row holding the Ctrl and Shift keys. Selects the range of rows between the previously selected row and the clicked one, preserving the previous selection.

You can simulate Ctrl- and Shift-clicks on grid rows 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, use successive Click calls with the desired row coordinates and the needed Shift parameter values.

An individual row can be selected by simulating a click on its indicator. The row indicators, however, are displayed only if the view’s OptionsView.ShowIndicator property is True. If so, you can determine the row indicator coordinates using the following statement:

viewObj.ViewInfo.RowsInfo.GetInfoByHandle(RowIndex).IndicatorRect

Here, viewObj is the grid view in which the row resides; for grids that do not work in the master detail mode it should be gridObj.MainView. The RowIndex parameter specifies the zero-based index of the desired row. The returned object is a .NET System.Drawing.Rectangle object that contains grid-relative coordinates of the specified cell.

Below is an example that illustrates how to select multiple rows in the XtraGrid control by simulating Ctrl- and Shift-clicks on row indicators. It works with the GridTutorials sample application that is shipped with the Developer Express XtraGrid Suite. The example contains four routines:

  • Main is the “main” script routine. It obtains the scripting object corresponding to the XtraGrid control and calls SelectRange and SelectRows to select multiple rows in the grid.
  • SelectRange - Selects the specified range of rows in the grid. It has the following parameters:
    • Grid - Specifies the tested XtraGrid control.
    • View - Specifies the grid view in which the selection should be performed. If the null value (Nothing in VBScript) is passed in this parameter, the main (top-level) grid view is used.
    • StartRowIndex and EndRowIndex - Specify indexes (zero-based) of the first and the last rows of the range to be selected.
  • SelectRows - Selects the grid rows specified by their indexes. The parameters of this routine are similar to those of the SelectRange routine, except for the RowIndexes parameter that specifies an array containing indexes of rows to be selected.
  • ClickRowIndicator - A helper routine that simulates a click on a row indicator.

Using XtraGrid’s Internal Methods

The XtraGrid control has a number of internal methods that can be used for selecting or unselecting multiple rows. They are listed in the table below:

Method Description
viewObj.SelectRow (RowIndex) Selects the row specified by its index, preserving the previous selection.
viewObj.SelectRange (StartRowIndex, EndRowIndex) Selects rows in the specified range, preserving the previous selection.
viewObj.SelectAll() Selects all rows within a view.
viewObj.UnselectRow (RowIndex) Unselects the specified row.
viewObj.ClearSelection() Unselects all selected rows in a view.

The following example demonstrates how you can use these methods in scripts. It performs the same actions as the previous example, but the implementation of the SelectRange and SelectRows routines is different.


Close

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox