本帖最后由 ncistcn 于 2010-06-07 17:48:25 编辑

解决方案 »

  1.   

    这里需要注意的问题是,在调用SortItems()方法之前,必须调用SetItemData( int nItem, DWORD dwData ) 方法来设置回调函数中使用到LPARAM lParam1, LPARAM lParam2
    MSDN中对于SetItemData()函数的解释如下:
    This function sets the 32-bit application-specific value associated with the item specified by nItem. This value is the lParam member of theLVITEM structure, as described in the Platform SDK.所以不调用SetItemData方法,直接去调用SortItem方法就会出现排序无效的结果.
      

  2.   


    m_lst.InsertColumn(0, _T("asdf"), LVCFMT_LEFT, 200);
    nIndex = m_lst.InsertItem(0, _T("公主"));
    m_lst.SetItemData(nIndex, nIndex);
    nIndex = m_lst.InsertItem(0, _T("人事"));
    m_lst.SetItemData(nIndex, nIndex);
    nIndex = m_lst.InsertItem(0, _T("于东生"));           //这里的0表示你插入第一行
    m_lst.SetItemData(nIndex, nIndex);nIndex = m_lst.InsertItem(0, _T("於東生"));           //这个应该插入在第二行,下标应该为1
    m_lst.SetItemData(nIndex, nIndex);
    nIndex = m_lst.InsertItem(0, _T("生"));               //这些也是
    m_lst.SetItemData(nIndex, nIndex);
    nIndex = m_lst.InsertItem(0, _T("東"));               //这里也是
    m_lst.SetItemData(nIndex, nIndex);
      

  3.   

    有LVS_SORTASCENDING的CListCtrl使用InsertItem插入数据时,会自动选择合适的位置插入。
      

  4.   

    InsertItem不是用于排序的吧