HeaderPane
Main
Hide
Share Link
Print

SortItemsEx

Sorts items using cell and item information.

C

BOOL WINAPI SftBox_SortItemsEx(HWND hwndCtl, LONG indexTC, int col, SFTBOX_SORTPROCEX lpfnCompareEx);

C++

BOOL CSftBox::SortItemsEx(LONG indexTC, int col, SFTBOX_SORTPROCEX lpfnCompareEx);

Parameters

hwndCtl

The window handle of the combo box control.

indexTC

The zero-based index of the item whose immediate dependent items will be sorted. This parameter can be -1, in which case all items at level 0 are sorted.

col

The zero-based column number whose text and cell data are to be sorted.

lpfnCompareEx

A pointer to a comparison callback routine of type SFTBOX_SORTPROCEX. This parameter may be NULL, in which case items are sorted in ascending order of their cell text.

Returns

The return value is TRUE if the function was successful, otherwise FALSE is returned. FALSE is returned if indexTC or col is not valid.

Comments

The SortItemsEx function sorts items using cell and item information.

The callback routine lpfnCompareEx is called to compare two items. It receives the window handle of the combo box, the cell text of both items in the column col, the application-specific values of both items (see SetItemData) and the application-specific values of both cells in the column col (see SFTBOX_CELL, cellData). The callback returns -1 if the first item is smaller than the second item, 0 if the items compare as being equal and 1 if the first item is greater than the second item.

The cell data allows items to be sorted by a value which differs from the text shown. For example, a cell can display a formatted date or number, while its cell data holds the value used for sorting.

If lpfnCompareEx is NULL, the cell text of the items is compared using the Windows function CompareString with the locale of the combo box (see SetLocale). This comparison is case sensitive.

Only immediate dependent items are sorted, i.e., the items on the level immediately below the item indexTC. Dependents of the items being sorted are moved with their parent item, but are not sorted. Use a separate SortItemsEx call for each parent item whose dependent items are to be sorted. TRUE is returned if there are no items to sort.

The sorting algorithm used preserves the order of an already sorted list, when many items have identical keys. This allows multiple columns to be sorted by sorting the least significant column first and the most significant column last.

The selected item remains selected. As its position may change, its index may be different once the items have been sorted (see GetCurSel).

SortItems can be used if the comparison does not require the application-specific values of the cells.

In a combo box control using a virtual data source, sorting functions cannot be used and an error is returned. The external virtual data source should be sorted instead.

Examples

C View entire sample code

        return;
    lpCol[0].colFlag &= ~(SFTBOX_COL_SORTED_ASC | SFTBOX_COL_SORTED_DESC);
    lpCol[0].colFlag |= fDescending ? SFTBOX_COL_SORTED_DESC : SFTBOX_COL_SORTED_ASC;
    SftBox_SetColumns(hwndBox, nCols, lpCol);
}

static void SortFonts(void)
{
    SftBox_SortItemsEx(m_hwndFonts, -1, 0, m_fFontsDescending ? SortStringsDescending : SortStringsAscending);
}

static void SortSizes(void)
{
    SftBox_SortItemsEx(m_hwndSizes, -1, 0, m_fSizesDescending ? SortCellDataDescending : SortCellDataAscending);
}

C++ View entire sample code

        return;
    lpCol[0].colFlag &= ~(SFTBOX_COL_SORTED_ASC | SFTBOX_COL_SORTED_DESC);
    lpCol[0].colFlag |= fDescending ? SFTBOX_COL_SORTED_DESC : SFTBOX_COL_SORTED_ASC;
    box.SetColumns(nCols, lpCol);
}

void CMainDlg::SortFonts()
{
    m_Fonts.SortItemsEx(-1, 0, m_fFontsDescending ? SortStringsDescending : SortStringsAscending);
}

void CMainDlg::SortSizes()
{
    m_Sizes.SortItemsEx(-1, 0, m_fSizesDescending ? SortCellDataDescending : SortCellDataAscending);
}

See Also C/C++ API | Categories | Notifications


Last Updated 11/21/2026 - (email)
© 2026 Softel vdm, Inc.