static int CALLBACK ListCtrlCompare(LPARAM lParam1, LPARAM lParam2, LPARAM
lParamSort)
{
CListCtrl *pListCtrl = (CListCtrl *)lParamSort;
CString str1 = pListCtrl->GetItemText(lParam1,0);
CString str2 = pListCtrl->GetItemText(lParam2,0);
return 1;
}
...
m_pListCtrl = new CListCtrl;
VERIFY(m_pListCtrl->SubclassDlgItem(IDC_LIST,this));
m_pListCtrl->InsertItem(0,"1");
m_pListCtrl->SetItem(0,1,LVIF_TEXT,"D",0,0,0,0);
m_pListCtrl->InsertItem(1,"2");
m_pListCtrl->SetItem(1,1,LVIF_TEXT,"C",0,0,0,0);
m_pListCtrl->InsertItem(2,"3");
m_pListCtrl->SetItem(2,1,LVIF_TEXT,"B",0,0,0,0);
m_pListCtrl->InsertItem(3,"4");
m_pListCtrl->SetItem(3,1,LVIF_TEXT,"A",0,0,0,0);
m_pListCtrl->SortItems(ListCtrlCompare,(LPARAM)m_pListCtrl);
...
I add four items to the list control. When I call SortItems after adding
them the function ListCtrlCompare is called four times ( once for each item
? ). The problem is that when I step through with the debugger within the
function ListCtrlCompare, the parameters lParam1 and lParam2 ( which are
meant to be the indexes of the items in the list control being compared )
never change from 0. What is going on ?
Do these things only ever happen to me ? Has Microsoft neglected to tell me
that SortItems only works with the list style LVS_SECRETSQUIRREL ?
Ta.
Robert Quirk wrote:
Unfortunately, despite the confusing documentation, lParam1 and lParam2 are
item data, not item indexes. Use SetItemData() to set these parameters.
Bad example!
>.. the parameters lParam1 and lParam2 ( which are
>meant to be the indexes of the items in the list control being compared )
>never change from 0. What is going on ?
The example fails to tell you that you need to store some sort order
index in the list control's item data - the item data value is what's
passed to the sort callback, not the index of the item itself.
Dave
--
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.
David Lowndes <dav...@mvps.org> wrote in message
news:8lg25s03npoocka41...@4ax.com...