IMAPITable::SortTable

The IMAPITable::SortTable method orders the rows of the table based on sort criteria.

Quick Info

See IMAPITable : IUnknown.

HRESULT SortTable(
  LPSSortOrderSet lpSortCriteria,   
  ULONG ulFlags                     
);
 

Parameters

lpSortCriteria
[in] Pointer to an SSortOrderSet structure containing the sort criteria to apply. Passing an SSortOrderSet structure containing zero columns indicates that the table does not need to be sorted in any particular order.
ulFlags
[in] Bitmask of flags that controls the timing of the IMAPITable::SortTable operation. The following flags can be set:
TBL_ASYNC
Starts the operation asynchronously and returns before the operation completes.
TBL_BATCH
Defers the completion of the sort until the data in the table is required.

Return Values

S_OK
The sort operation was successful.
MAPI_E_BUSY
Another operation is in progress that prevents the sort operation from starting. Either the operation in progress should be allowed to complete or it should be stopped.
MAPI_E_NO_SUPPORT
The table does not support the type of sorting requested.
MAPI_E_TOO_COMPLEX
The table cannot perform the operation because the particular sort criteria pointed to by the lpSortCriteria parameter is too complicated. SortTable can return MAPI_E_TOO_COMPLEX when:

Remarks

The IMAPITable::SortTable method orders the rows in a table view. Whereas some tables support both standard and categorized sorting on a variety of sort key columns, other tables are more limited in their support. Address book providers commonly do not support table sorting. Message store providers commonly support sorting to the extent that they retain the sort order of folders that results when a full table — that is, a table with no restrictions — is sorted.

Some tables allow sorting to be done on any table column. Other tables do not; columns not included in the table view are unaffected by a SortOrder call. Some tables require that sort keys be built only with columns in the table's current column set.

A table will return either MAPI_E_NO_SUPPORT or MAPI_E_TOO_COMPLEX from SortTable when it cannot complete a sort operation for whatever reason.

When there are zero columns in the SSortOrderSet structure pointed to by the lpSortCriteria parameter, the table returns the current column set. The current sort order can be retrieved by calling the table's IMAPITable::QuerySortOrder method.

All bookmarks for a table are invalidated and should be deleted when a call to SortTable is made, and the BOOKMARK_CURRENT bookmark, indicating the current cursor position, should be set to the beginning of the table.

If sorting on a column containing a multivalued property without the MVI_FLAG flag set, the column's values are treated as a totally ordered tuple. A comparison of two multivalued columns compares the column elements in order, reporting the relation of the columns at the first inequality, and returns equality only if the columns compared contain the same values in the same order. If one column has fewer values than the other, the reported relation is that of a null value to the other value.

Notes to Callers

SortTable operates synchronously unless you set one of the flags. If you set the TBL_BATCH flag, SortTable postpones the sort operation unless you request the data. If the TBL_ASYNC flag is set, SortTable operates asynchronously, potentially returning before the completion of the operation.

Call the IMAPITable::Abort method to stop an asynchronous operation in progress if your sort must be done immediately. If SortTable cannot proceed because one or more asynchronous operations on the table are in progress, it returns MAPI_E_BUSY.

For best performance, call SetColumns to customize the table's column set and Restrict to limit the number of rows in the table before calling SortTable to perform the sort.

Whenever SortTable fails, the sort order that was in effect before the failure is still in effect.

See Also

IMAPITable::Abort, IMAPITable::GetRowCount, IMAPITable::QueryColumns, IMAPITable::QuerySortOrder, IMAPITable::SetColumns, SSortOrderSet