如何使LIST控件排序

解决方案 »

  1.   

    http://www.codeproject.com/listctrl/sortlistctrl.asp
      

  2.   

    Example// Sort the item in reverse alphabetical order.
    static int CALLBACK 
    MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
    {
       // lParamSort contains a pointer to the list view control.
       // The lParam of an item is just its index.
       CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
       CString    strItem1 = pListCtrl->GetItemText(lParam1, 0);
       CString    strItem2 = pListCtrl->GetItemText(lParam2, 0);   return strcmp(strItem2, strItem1);
    }void snip_CListCtrl_SortItems()
    {
       // The pointer to my list view control.
       extern CListCtrl* pmyListCtrl;
       int i=pmyListCtrl->GetItemCount();
       while(i--)pmyListCtrl->.SetItemData(i,i); 
       // Sort the list view items using my callback procedure.
       pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
    }