Guidance Forums / wxWidgets (wxWindows) in C++ / wxListCtrl::SortItems()

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. wxListCtrl::SortItems()
Posted by: 2004-02-08 08:32:12
I'm  new to wxWindows, but I'm progressing along.  However,  I've come to an impass with respect to sorting items in a wxListCtrl.  The documentaion says that I need to call the method SortItems(wxListCtrlCompare fn, long data) to sort the items.

I need to define the function wxListCtrlCompare with the following prototype
int wxCALLBACK wxListCompareFunction(long item1, long item2, long sortData)

My problem is that I can't seem to figure out how to use the item1, item2 and sortData arguments inside my compare function to do what I want for sorting.  The function provided in the samples does no give me inough info.  All it includes is:

int wxCALLBACK MyCompareFunction(long item1, long item2, long sortData)
    // inverse the order
    if (item1 < item2) return -1;
    if (item1 > item2) return 1;
    return 0;
I have a wxListCtrl object that I've configured to have several columns in the report view.  I want to be able to sort the items in the wxListCtrl alphabetically based on the values in the 1st column only, the 2nd column only, 3rd column only, etc.  I don't know how to use "item1" and "item2" and "sortData" to obtain the comparison I want in order to return the proper value (-1, 0, or 1) for my function.  All I know is that "itemX" is the "client data" and "NOT the index".  Does any body have any insight into how to do this, or have any sample code I could be directed to to figure this out.  

Thanks for any help you can provide.
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Fri 2024-7-19  Guidance Laboratory Inc. Hits:0