Click to See Complete Forum and Search --> : List View Question (Win32)


MrDoomMaster
November 25th, 2004, 06:08 PM
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!

darwen
November 25th, 2004, 06:51 PM
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.

MrDoomMaster
November 25th, 2004, 08:50 PM
I don't quite understand...

Could you explain further?

Andreas Masur
November 26th, 2004, 02:22 AM
[ Moved thread ]

VictorN
November 26th, 2004, 03:28 AM
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...