One of the actions you'll perform most often on a grid is selecting
cells. This article provides an example that selects grid cells on the
QuantumGrid control by Developer Express.
To perform this task, we will use the following internal properties of the TcxGrid object (TcxGrid is the class name of the QuantumGrid control):
ViewObj.Controller.FocusedColumnIndex - Using these properties you can move the focus to the specified column or obtain the column object that corresponds to the focused column in a view (the QuantumGrid control can contain several row levels. Each level has a view that defines how the data is displayed).
FocusedColumn property returns the column object. The
FocusedColumnIndex returns the index (zero-based) of the focused column.
ViewObj.Controller.FocusedRowIndex - Specifies the index of the focused row for a view.
GridObj.ActiveView - Returns the view object that corresponds to the root level.
Note: in order for TestComplete to be able to access these properties, the tested application must be compiled as an Open Application with debug information.
In addition, the property code must be included into the application’s binary file. The problem is that Delphi’s (or C++Builder’s) smart linker excludes methods and properties that are not used within the application. So, it is possible that the mentioned properties are not included into the application’s executable, or the application provides limited access to them (for instance, a read/write property can be seen as read-only or write-only).
To solve the problem, you can create a virtual method in your code that will call the needed properties. For example, you can use the following code:
In the example, we typecast the
cxGrid1.ActiveView object to the
TcxGridDBTableView type. In your application, the type name must conicinde with the view data type.
Note that the cell selection is only possible if the grid displays data in row selection mode. This mode is active, if the view’s
ViewObj.OptionsView.CellSelect is set to False. If you are not sure which mode the tested grid functions, you may ask the tested application’s developer. Also, you can determine the mode visually by watching the grid’s behavior when you are navigating through the records. If the grid highlights whole rows rather than individual cells, then the row selection mode is active and you cannot simulate the cell selection.
Below is a sample code demonstrates the cell selection within the QuantumGrid control. The sample contains the following routines: