I have a listview control in my project, runs in Visual C++ 6.0, that I want to make a sort based on column click. It works good when I have <1000 entries but when it goes over 1000 entries the sorting performance goes down. It takes about 10-15 seconds to sort the listview.
My way of making the sort is to use the SortItems() function for the listview in the OnColumnClick.
SortItems(SortFunc, (DWORD)this);
And my callback function looks like this:
int CALLBACK SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
_CListCtrl* pListCtrl = (_CListCtrl*) lParamSort;
LPITEM pData1 = (LPITEM)lParam1;
LPITEM pData2 = (LPITEM)lParam2;
int idx = pListCtrl->IndexFromValue(pData1->nRowID);
int idx2 = pListCtrl->IndexFromValue(pData2->nRowID);
CString strItem1 = pListCtrl->GetItemText(idx, pListCtrl->GetSortColumn());
CString strItem2 = pListCtrl->GetItemText(idx2, pListCtrl->GetSortColumn());
if(pListCtrl->GetSortAscending())
{
return pListCtrl->typeSafeCompare(strItem2, strItem1) < 0;
} else
return pListCtrl->typeSafeCompare(strItem2, strItem1);
}
Is there any other type of sorting that has a better performance or am I stuck with this type of sorting?
appriciate all help I can get :)
brgs
Niklas