CGXGridCore::SortRows

virtual void SortRows(CGXRange sortRange, CGXSortInfoArray& sortInfo, UINT flags = GX_UPDATENOW);

sortRange

Specifies the range of cells to be sorted. You can limit the range of rows with CGXRange().SetRows(nFromRow, nToRow) if you only want to sort certain rows in your grid (e.g., if you have several frozen rows that should not be sorted).

sortInfo

This is an array of CGXSortInfo objects that contain the sort information for each key.

flags

  • Specifies the update technique:

  • GX_UPDATENOW - updates the window immediately

GX_INVALIDATE - invalidates the window

Remarks

Call this method to sort the rows in a grid and specify the sort key with the sortInfo parameter.

Here is how you should call SortRows:

a) Specify the sort-information
CGXSortInfoArray array;
array.SetSize(1);      // 1 key only (you can also have more keys)
array[0].nRC = nCol;   // column nCol is the key
sortInfo[0].sortType = CGXSortInfo::autodetect;   // the grid
      // will determine if the key is a date, numeric or
      // alphanumeric value
sortInfo[0].sortOrder = CGXSortInfo::ascending;
      // sort ascending
b) Call SortRows to let the grid do the sorting
   SortRows(CGXRange().SetTable(), sortInfo);

With each key you have the possibility of specifying the following parameters:

  • nRC – Specifies the row with the key values

  • sortType – Specifies the sort type (numeric, alphanumeric, date, autodetect)

  • sortOrder – Specifies the sort order (ascending, descending)

  • bCaseTRUE if case sensitive, FALSE if not

  • dwCookie - 32-Bit value you can pass as cookie (e.g., if you have overridden GetSortKey)

The default implementation of SortRows will loop through all columns in sortRange and determine the sort keys. If you specified CGXSortInfo::autodetect as sort type, SortRows will analyze all values. If all values in a column are valid date values, SortRows will perform a sort by date. If all values in a column are valid numbers, it will perform a number sort. Otherwise, it will do a alphanumeric sort.

After the keys have been sorted, SortRows will build up an array with the new row order and will pass this array to MoveDataRows. MoveDataRows creates undo information and calls the virtual method StoreMoveDataRows to rearrange the data structure attached to the grid so that it reflects the new row order. The display will be updated and a hint sent to other views attached to the document with the call to UpdateMoveDataRows.

If you want to modify the key values returned for specific cells, you can override GetSortKey.

If you are using the grid with your own data structure, you should override StoreMoveDataRows and rearrange your data to reflect the changes.

Note

If your grid is attached to a data source which supports sorting itself, you might take advantage of the sorting feature of the data source. In this case, you should override SortRows and let your data source do the sorting.

For example, with DAO and ODBC grids, the SortRows method is implemented in a way that it only requeries the SQL data source with the SQL “order by” statement.

Control-Factory Specific ->

This method has been implemented using the abstraction mechanism as discussed in the chapter "Reducing the size of your application" in the user's guide. A call to the ImplementGridSort method from within the control factory class' InitializeGridComponents method will make the concrete implementation of this method available to your application.

If no concrete implementation is available this method performs no action. A warning will be displayed in the debug window.

END Control-Factory Specific

See Also

 CGXGridCore::MoveDataRows  CGXGridCore::StoreMoveDataRows  CGXGridCore::UpdateMoveDataRows  CGXGridCore::GetSortKey

CGXGridCore

 Class Overview |  Class Members