CTreeCtrl::SortChildrenCB

BOOL SortChildrenCB( LPTVSORTCB pSort );

Return Value

Nonzero if successful; otherwise 0.

Parameters

pSort

Pointer to a TVSORTCB structure.

Remarks

Call this function to sort tree view items using an application-defined callback function that compares the items.

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.
static 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.
   CTreeCtrl* pmyTreeCtrl = (CTreeCtrl*) lParamSort;
   CString    strItem1 = pmyTreeCtrl->GetItemText((HTREEITEM) lParam1);
   CString    strItem2 = pmyTreeCtrl->GetItemText((HTREEITEM) lParam2);

   return strcmp(strItem2, strItem1);
}

   // The pointer to my tree control.
   extern CTreeCtrl* pmyTreeCtrl;
   TVSORTCB tvs;

   // Sort the tree control's items using my
   // callback procedure.
   tvs.hParent = TVI_ROOT;
   tvs.lpfnCompare = MyCompareProc;
   tvs.lParam = (LPARAM) pmyTreeCtrl;

   pmyTreeCtrl->SortChildrenCB(&tvs);

CTreeCtrl OverviewClass MembersHierarchy Chart

See Also   CTreeCtrl::SortChildren