Working With Developer Express QuantumGrid - Selecting Cells

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.FocusedColumn or 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).
  • The 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:

  • Main - The “main&Rdquo; routine of the sample. It obtains the scripting object that corresponds to the tested grid control and then calls the SelectGridCell routine that performs the selection.
  • SelectGridCell - Selects the specified grid cell. The routine uses the following parameters:
    • grid - The scripting object that corresponds to the tested grid.
    • view - The view object that contains the desired cell. If this parameter is Nothing (VBScript), null (JScript, C++Script, C#Script) or nil (DelphiScript), the routine assumes that you are working with the view associated with the root level.
    • rowIndex - A zero-based index of the desired row.
    • columnId - Either caption of the desired column, or column index (zero-based) among other visible columns.

    The routine performs the following actions:

    • If the view parameter is not specified, the routine uses the internal ActiveView property of the grid control to obtain the view that corresponds to the grid’s root level.
    • Then, the routine calls the GetColumn function to obtain the column object, which corresponds to the desired column, and assigns this object to the Controller.FocusedColumn property of the specified view.
    • Then, the routine assigns the specified row index to the view’s Controller.FocusedRowIndex property.
  • GetColumn - A helper routine that returns a column object by the column’s caption or by column index among other visible columns (the index is zero-based).

Close

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

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