CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 1999
    Posts
    3

    Sorting in ListView Control

    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
    [email protected]


  2. #2
    Join Date
    Jul 1999
    Posts
    19

    Re: Sorting in ListView Control

    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 ¨

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured