CGXGridCore::SortCols
virtual void SortCols(CGXRange sortRange, CGXSortInfoArray& sortInfo, UINT flags = GX_UPDATENOW);
sortRange
Specifies the range of cells to be sorted. You can limit the range of columns with CGXRange().SetCols(nFromCol, nToCol) if you only want to sort certain columns in your grid (e.g., if you have several frozen columns 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 columns in a grid and specify the sort key with the sortInfo parameter.
Here is how you should call SortCols:
a) Specify the sort-information
CGXSortInfoArray array;
array.SetSize(1); // 1 key only (you can also have more keys)
array[0].nRC = nRow; // row nRow 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 SortCols to let the grid do the sorting
SortCols(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)
- bCase – TRUE 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 SortCols will loop through all rows in sortRange and determine the sort keys. If you specified CGXSortInfo::autodetect as sort type, SortCols will analyze all values. If all values in a row are valid date values, SortCols will perform a sort by date. If all values in a row are valid numbers, it will perform a number sort. Otherwise, it will do an alphanumeric sort.
After the keys have been sorted, SortCols will build up an array with the new column order and will pass this array to MoveDataCols. MoveDataCols creates undo information and calls the virtual method StoreMoveDataCols to rearrange the data structure attached to the grid so that it reflects the new column order. The display will be updated and a hint sent to other views attached to the document with the call to UpdataMoveDataCols.
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 StoreMoveDataCols and rearrange your data to reflect the changes.
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::MoveDataCols CGXGridCore::StoreMoveDataCols CGXGridCore::UpdateMoveDataCols CGXGridCore::GetSortKey