Click to See Complete Forum and Search --> : Sorting in ListView Control
yimin Zhou
July 7th, 1999, 10:03 AM
I want to sort a listview control by clicking a column header. What I did was that I used the macro ListView_SortItems(hwnd, pfnCompare, lParamSort) when a notification for header click was received. Also I wrote my own compare as Compare(lParam1, lParam2, lParamSort). The problem is that every time the Compare function gets called, it gets two NULL parameters for the first two parameters. Does anybody have some hint for this?
Thanks,
Yimin
yz@prucka.com
J Diamond
July 7th, 1999, 10:34 AM
What you get in lParam1 is the item data for the first item to compare, and in lParam2 the item data of the second. Item data is the DWORD you can attach to every item using SetItemData.
For instance, you can set this arbitrary DWORD to point to a data structure, allocated for each item in your list view, and then, derefernce this pointer (by doing (MyStructure*)lParam1) to access the data structure and use it in the sort function (the compare function).
Another thing. Use the third parameter (lParamSort) to fully control the sort (like up/down sort, etc.)
J ¨
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.