CTreeCtrl::SortChildrenCB
Call this function to sort tree view items using an application-defined callback function that compares the items.
BOOL SortChildrenCB(
LPTVSORTCB pSort
);
Parameters
- pSort
Pointer to a TVSORTCB structure.
Return Value
Nonzero if successful; otherwise 0.
Remarks
The structure's comparison function, lpfnCompare, must return a negative value if the first item should precede the second, a positive value if the first item should follow the second, or zero if the two items are equivalent.
The lParam1 and lParam2 parameters correspond to the lParam member of the TVITEM structure for the two items being compared. The lParamSort parameter corresponds to the lParam member of the TV_SORTCB structure.
Example
// Sort the item in reverse alphabetical order.
int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
// lParamSort contains a pointer to the tree control.
// The lParam of an item is just its handle,
// as specified with SetItemData
CTreeCtrl* pmyTreeCtrl = (CTreeCtrl*)lParamSort;
CString strItem1 = pmyTreeCtrl->GetItemText((HTREEITEM)lParam1);
CString strItem2 = pmyTreeCtrl->GetItemText((HTREEITEM)lParam2);
return strItem2.Compare(strItem1);
}
TVSORTCB tvs;
// Sort the tree control's items using my
// callback procedure.
tvs.hParent = TVI_ROOT;
tvs.lpfnCompare = MyCompareProc;
tvs.lParam = (LPARAM)&m_TreeCtrl;
m_TreeCtrl.SortChildrenCB(&tvs);
Requirements
Header: afxcmn.h