CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Location
    Texas, USA
    Posts
    1,206

    List View Question (Win32)

    Please use Win32 only, no MFC. Thank you.

    Since I sort my items in my list view, it is pretty much impossible to use an item's index value to reference it, considering that an items index is based on its position in the list view, from top to bottom.

    To compensate for this, I reference an item based on its lParam value in LVITEM struct. When I add an item, I configure the lParam item of the LVITEM structure with a unique value that I can use to reference the item, no matter what position it has in the list view.

    The only problem is that most of the list view macros supplied by Windows API requires the index value of the item, not the lparam. Hence I need a function that can do one of the following:

    1. A function that accepts an lParam value and returns the item's index value.

    2. A function that accepts an lParam value and returns the item's LVITEM structure, which will contain the item's index AND lparam value, along with several other properties.

    I hope someone can help me out, because I"ve been reading MSDN and I've come up with nothing helpful yet.

    Thank you!

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: List View Question (Win32)

    Actually, it's the same in MFC but there you go.

    Sorting is done on the data of each item... as you know.

    To sort I tend to first load all the item's data into a map (if you're not using MFC then use STL instead).

    Then set all the items data appropriately and run the sort.

    Then put all the items data back to their original values.

    Using a map this'll be about as efficient as you're going to get.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Feb 2004
    Location
    Texas, USA
    Posts
    1,206

    Re: List View Question (Win32)

    I don't quite understand...

    Could you explain further?

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: List View Question (Win32)

    [ Moved thread ]

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: List View Question (Win32)

    Quote Originally Posted by MrDoomMaster
    Please use Win32 only, no MFC. Thank you.

    Since I sort my items in my list view, it is pretty much impossible to use an item's index value to reference it, considering that an items index is based on its position in the list view, from top to bottom.

    To compensate for this, I reference an item based on its lParam value in LVITEM struct. When I add an item, I configure the lParam item of the LVITEM structure with a unique value that I can use to reference the item, no matter what position it has in the list view.

    The only problem is that most of the list view macros supplied by Windows API requires the index value of the item, not the lparam. Hence I need a function that can do one of the following:

    1. A function that accepts an lParam value and returns the item's index value.

    2. A function that accepts an lParam value and returns the item's LVITEM structure, which will contain the item's index AND lparam value, along with several other properties.

    I hope someone can help me out, because I"ve been reading MSDN and I've come up with nothing helpful yet.

    Thank you!
    I think, the ListView_FindItem macro (or sending the message LVM_FINDITEM to your list control) is what you need. See MSDN for additional info...

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