Menu

CListView::SortItems

Help
Gordon Ahn
2014-10-01
2014-10-03
  • Gordon Ahn

    Gordon Ahn - 2014-10-01

    Hi David.

    With my example as follows:

    int CALLBACK CMyList::CompareFunction( LPARAM lParam1, LPARAM lParam2, LPARAM lParamData )
    {
    CMyList* pListTable = reinterpret_cast<pbmalwaretable*>( lParamData );</pbmalwaretable*>

    ItemData* pid1 = reinterpret_cast<ItemData*>( lParam1 );
    ItemData* pid2 = reinterpret_cast<ItemData*>( lParam2 );
    
    LPCTSTR pszText1 = pid1->arrpsz[ pListTable->m_nSortColumn ];
    LPCTSTR pszText2 = pid2->arrpsz[ pListTable->m_nSortColumn ];
    
    
    if( IsNumber( pszText1 ) )
        return pListTable->m_bSortAscending ? NumberCompare( pszText1, pszText2 ) : NumberCompare( pszText2, pszText1 );
    else if( IsDate( pszText1 ) )
        return pListTable->m_bSortAscending ? DateCompare( pszText1, pszText2 ) : DateCompare( pszText2, pszText1 );
    else
        // text.
        return pListTable->m_bSortAscending ? lstrcmp( pszText1, pszText2 ) : lstrcmp( pszText2, pszText1 );
    

    }

    void CMyList::SortTables(void)
    {
    SortItems(CompareFunction, reinterpret_cast<dword>( this ) );
    }</dword>

    In comparefunction, lParam1 is 0 and lParam2 is 0 too.

    So, I can't sort listitems..
    Why?

    -- Gordon Ahn.

     
  • David

    David - 2014-10-03

    Hi Gordon,

    The lParam1 parameter is the 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.

    I'm guessing these lParam values weren't specified in the LVITEM structure when these were added to the list. The lParam values are often pointers to the information in the list.

    The lParamData parameter is usually used to determine which column in the list is used for sorting, and the direction of the sort.

    CListView::SortItems wraps the listview_sortitems macro. Coding examples using listview_sortitems can be found on Google.

    Best regards,
    David

     

Log in to post a comment.

MongoDB Logo MongoDB