Sorting Data in Developer Express QuantumGrid
Test and Monitor | Posted April 25, 2007

The data displayed by the QuantumGrid control can be sorted by one or several columns. Typically, users specify the sorting column and change the direction (ascending or descending) by clicking the column caption. However, creating script code that will simulate mouse clicks over column captions is not an easy task. The problem is that you will have to calculate the coordinates of the click and this is not easy, especially if the column belongs to a child level.

To simulate the sorting, you can use the internal methods and properties of the TcxGrid object (TcxGrid is the class name of the QuantumGrid control). This approach is a lot easier and stable than simulating the mouse click.

To sort the grid data by a column, the test script should perform the following actions:

  • Get the column object that corresponds to the desired column.
  • Use the SortOrder property of the column object to specify the desired sorting order:
    • 1 - Ascending
    • 2 - Descending
    • 0 - No sorting

  • Note that assigning 1 or 2 to the SortOrder property of a column does not automatically cancel sorting by other column(s).

To perform these actions, TestComplete should have access to internal methods and properties of the TcxGrid object. That is, the tested application must be compiled as an Open Application with debug information.

The following sample demonstrates how to use internal methods and properties to sort grid data. The sample contains the following routines:

  • Main - The “main” routine of the sample. It obtains the scripting object that corresponds to the tested grid object and then calls the SortAscending, SortDescending and CancelSorting routines to sort the grid data.
  • SortAscending, SortDescending, CancelSorting - Sets the ascending or descending sorting order for a column or cancels the sorting. All these routines use the following parameters:
    • grid - The scripting object that corresponds to the tested grid control.
    • view - The view object that contains the desired column. 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.
    • columnId - The caption or a zero-based index of the desired column among other visible columns.

    The routines perform the following actions:

    • Call the GetColumn function to obtain the column object that corresponds to the desired column.
    • Assign the appropriate constant to the SortOrder property of the column objects.
  • GetColumn - Helper routine that is used to obtain the object that provides program interface to the desired column.

Here is the sample code:


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