In my previous article, I explained how to select multiple rows in Developer Express XtraGrid controls. You may then need to process the selected records in a certain way. To work with the selected records, you can use the following properties and methods of the grids view that contains the selection:
viewObj.GetSelectedRows() - Returns an array holding indexes of rows (cards) currently selected in the view. Note that the returned array is a .NET object, so you cannot access its elements using simple indexing. You should use the objects internal properties or methods instead.
viewObj.SelectedRowsCount - Returns the number of currently selected rows (cards).
Note: In order for TestComplete to be able to access the mentioned methods, the .NET Open Application Support plug-in is installed and enabled.
Below is an example that demonstrates how you can work with selections in the XtraGrid control. This example works with the GridTutorials sample application shipped with the Developer Express XtraGrid Suite. The script contains the following routines:
Main - The main routine of the example. It obtains the scripting object corresponding to the XtraGrid control, selects a range or rows, calls
GetSelectedRowIndexes to get indexes of selected rows, and then post texts in the selected rowss Product column to the test log.
SelectRange2 - Selects the specified range of rows in the grid. For more information on this routine, see Selecting Multiple Rows in Developer Express XtraGrid.
GetSelectedRowIndexes - Returns an array containing zero-based indexes of rows (cards) selected in the grid. The routine has two parameters:
- Grid - The tested XtraGrid control.
- View - The grids view in which the selected rows (cards) reside. If the null value (
Nothing in VBScript) is passed in this parameter, it means that the selection belongs to the main (top-level) view.
GetCellText - Returns the text displayed in the specified cell. This routine was defined in Getting Cell Values in Developer Express XtraGrid.
GetColumn - A helper function that returns the column object specified by its caption or zero-based index.