我每次向CListCtrl中添加项目都向第一行加。当加入后,如何能让CListCtrl自动按照A列值进行排序显示,如果A列值相等则按B列值排序。(自动的,不是按上面的钮)。

解决方案 »

  1.   

    可以在程序中做一个项目的list全局变量,当插入新的项目时,先插入到list中,sort后,CListCtrl中的数据重新导入。
      

  2.   

    CListCtrl::SortItems  Sorts list view items using an application-defined comparison function.BOOL SortItems(
       PFNLVCOMPARE pfnCompare,
       DWORD_PTR dwData 
    );
     
    Parameters
    pfnCompare
    Address of the application-defined comparison function. The comparison function is called during the sort operation each time the relative order of two list items needs to be compared. The comparison function must be either a static member of a class or a stand-alone function that is not a member of any class.dwData
    Application-defined value that is passed to the comparison function.Return Value
    Nonzero if successful; otherwise zero.Res
    The index of each item changes to reflect the new sequence.The comparison function has the following form:int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, 
       LPARAM lParamSort);
     
    The comparison function 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 parameter is the 32-bit value associated with the first item being compared, and the lParam2 parameter is the value associated with the second item. These are the values that were specified in the lParam member of the items' LVITEM structure when they were inserted into the list. The lParamSort parameter is the same as the dwData value.ExampleMyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
    {
       return lParam1 < lParam2;
    }
     
      

  3.   

    用SortItems
    传过一个比较函数.
    就可以自动排序了.