API for MFC Sorting Controls
SortComboBox

Copyright 2016 by David Wincelberg

Window Styles

Recommended vertical scroll
Optional sort

For an owner-draw combo box with strings, select has-strings and implement DrawItem and MeasureItem. CompareItem will not be called.

ComboBoxData

CComboBoxData();

constructor

ComboBoxOrder

CComboBoxOrder (CStringOrder* pStringOrder = nullptr, bool bHandleDelete = true);

constructor

pStringOrder pointer to a string-order object
bHandleDelete specifies whether to delete this string-order object

void SetStringOrder (CStringOrder* pStringOrder, bool bHandleDelete = true);

Sets the string-order for a list box.

pStringOrder pointer to a string-order object
bHandleDelete specifies whether to delete this string-order object

bool ValidStringOrder()

Returns true if the string-order object is not null.

CStringOrder* GetStringOrder();

Returns the string-order object.

virtual int Compare (CString& strItem1, CComboBoxData* pData1, CString& strItem2, CComboBoxData* pData2);

Returns an integer that specifies order of the strings or the corresponding data items.

strItem1 reference to the first string
pData1 pointer to the first data item
strItem2 reference to the second string
pData2 pointer to the second data item

SortComboBox

CSortComboBox (CComboBoxOrder* pComboBoxOrder = nullptr, bool bHandleDelete = true);

constructor

pComboBoxOrder pointer to a sort-order object
bHandleDelete specifies whether to delete this sort-order object

CSortComboBox (CStringOrder* pStringOrder, bool bHandleDeleteInner = true, bool bHandleDeleteOuter = true);

constructor

pComboBoxOrder pointer to a string-order object
bHandleDeleteInner specifies whether to delete this string-order object
bHandleDeleteOuter specifies whether to delete the sort-order object

void SetSortOrder (CComboBoxOrder* pComboBoxOrder, bool bHandleDelete = true);

Sets the sort-order to the specified value.

pComboBoxOrder pointer to sort-order object
bHandleDelete specifies whether to delete this sort-order object

void SetStringOrder (CStringOrder* pStringOrder, bool bHandleDelete = true);

Sets the string-order to the specified value.

pStringOrder pointer to string-order object
bHandleDelete specifies whether to delete this string-order object

int AddString (LPCTSTR lpszItem, CComboBoxData* pComboBoxData = nullptr);
int InsertString (int nIndex, LPCTSTR lpszItem, CComboBoxData* pComboBoxData = nullptr);

Same as for CComboBox with an optional parameter for specifying a combo-box data item

int DeleteString (UINT nIndex);
void ResetContent();
int SetItemData (int nIndex, DWORD dwItemData);
DWORD GetItemData (int nIndex) const;
int SetItemDataPtr (int nIndex, void* pData);
void* GetItemDataPtr (int nIndex) const;

Same as for CComboBox

int SetItemDataObjPtr (int nIndex, CComboBoxData* pComboBoxData);

Stores user data as a pointer to a CComboBoxData object.
Copies the data values from the old data object and deletes it. pComboBoxData should be from a subclass of CComboBoxData.

nIndex index into the list box
pComboBoxData pointer to a data object

CComboBoxData* GetItemDataObjPtr (int nIndex) const;

Retrieves user data as a pointer to a CComboBoxData object.

nIndex index into the list box