CListCtrl::SortItems example 
Author Message
 CListCtrl::SortItems example

Dear Group,

Would anyone have a (small) working example of using
CListCtrl::SortItems( PFNLVCOMPARE pfnCompare, DWORD
dwData ) with the CALLBACK function implementation ?

I have used the example listed at

http://www.*-*-*.com/
url=/library/en-
us/vclib/html/_mfc_CListCtrl.3a3a.SortItems.asp

which indeed calls the callback function

MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM
lParamSort)
{
   // lParamSort contains a pointer to the list view
control.
   CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
   CString    strItem1 = pListCtrl->GetItemText(lParam1,
0);
   CString    strItem2 = pListCtrl->GetItemText(lParam2,
0);

   return strcmp(strItem2, strItem1);

Quote:
}

However, the callback parameters lParam1 and lParam2 are
always 0 and 0, and therefore no sorting is taking place.

Any ideas ?

Michael



Sun, 11 Sep 2005 17:23:09 GMT  
 CListCtrl::SortItems example
It's most likely because SetItemData() is not being used or is being used
incorrectly.


Quote:
> Dear Group,

> Would anyone have a (small) working example of using
> CListCtrl::SortItems( PFNLVCOMPARE pfnCompare, DWORD
> dwData ) with the CALLBACK function implementation ?

> I have used the example listed at

> http://msdn.microsoft.com/library/default.asp?
> url=/library/en-
> us/vclib/html/_mfc_CListCtrl.3a3a.SortItems.asp

> which indeed calls the callback function

> MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM
> lParamSort)
> {
>    // lParamSort contains a pointer to the list view
> control.
>    CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
>    CString    strItem1 = pListCtrl->GetItemText(lParam1,
> 0);
>    CString    strItem2 = pListCtrl->GetItemText(lParam2,
> 0);

>    return strcmp(strItem2, strItem1);
> }

> However, the callback parameters lParam1 and lParam2 are
> always 0 and 0, and therefore no sorting is taking place.

> Any ideas ?

> Michael



Sun, 11 Sep 2005 18:50:15 GMT  
 CListCtrl::SortItems example

Quote:

> Dear Group,

> Would anyone have a (small) working example of using
> CListCtrl::SortItems( PFNLVCOMPARE pfnCompare, DWORD
> dwData ) with the CALLBACK function implementation ?

> I have used the example listed at

> http://msdn.microsoft.com/library/default.asp?
> url=/library/en-
> us/vclib/html/_mfc_CListCtrl.3a3a.SortItems.asp

> which indeed calls the callback function

> MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM
> lParamSort)
> {
>    // lParamSort contains a pointer to the list view
> control.
>    CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
>    CString    strItem1 = pListCtrl->GetItemText(lParam1,
> 0);
>    CString    strItem2 = pListCtrl->GetItemText(lParam2,
> 0);

>    return strcmp(strItem2, strItem1);
> }

> However, the callback parameters lParam1 and lParam2 are
> always 0 and 0, and therefore no sorting is taking place.

The lParams are the data of lParam in LVITEM, not the iItem.
You would need to set the lParam to the iItem value, ( or use
SetItemData( itemCount ) as David mentioned), when you insert the items
to use it as the example works.

And the catch, your lParams no longer equal iItem when you get back from
the sort.\

Best, Dan.



Sun, 11 Sep 2005 21:14:32 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How do I code CListCtrl::SortItems

2. Probs on CompareFunc CListCtrl SortItems

3. CListCtrl::SortItems

4. CListCtrl SortItems - CALLBACK lparam values always 0

5. calling CListCtrl::SortItems() twice in a row

6. CListCtrl::SortItems() problems

7. CListCtrl::SortItems() doesn't work!

8. Does CListCtrl::SortItems() work?

9. CListCtrl::SortItems

10. CListCtrl.SortItems

11. Why isn't CListCtrl::SortItems working ?

12. CListCtrl SortItems ??

 

 
Powered by phpBB® Forum Software