REALLY annoying listview problem 
Author Message
 REALLY annoying listview problem

I insert a bunch of items into a listview. As I do so, I set the iItem
member of the LVITEM structure to a number that I will need later. So now
there's a bunch of items in memory, each represented by an LVITEM structure.

The text of the listview items are then displayed in the listview. Because
the listview sorts alphabetically, the order in which the item text are
displayed is not necessarily the order in which they were added to the
listview.

Then, the user selects an item and clicks ok.

When I handle the OK click, I use ListView_FindNextItem to get the index of
the selected item.

I then need to get the LVITEM structure corresponding to the selected item.
The problem is, I can't figure out how to do this! There's a
ListView_GetItem function, but to use it you need to know the iItem value of
the LVITEM you are looking for, and I don't have this info. All I have is
the index of the selected item based on the DISPLAY order.

I guess I could get the text of the selected item, and then search for the
item with that text, but that seems very kludgy.

Any ideas? This seems like a glaring error. Thanks very much.



Wed, 03 Dec 2003 08:15:51 GMT  
 REALLY annoying listview problem
On Fri, 15 Jun 2001 17:15:51 -0700, "David G."

Quote:

>Then, the user selects an item and clicks ok.

>When I handle the OK click, I use ListView_FindNextItem to get the index of
>the selected item.

So you have an "int" value here.

Quote:
>I then need to get the LVITEM structure corresponding to the selected item.
>The problem is, I can't figure out how to do this ! There's a
>ListView_GetItem function, but to use it you need to know the iItem value of
>the LVITEM you are looking for, and I don't have this info.

This item value is the same as the index value returned in the call to
ListView_FindNextItem.  So:

int item_index = ListView_FindNextItem(blah)...

// Make sure item_index isn't -1

LVITEM   lvi = {0};

lvi.mask = LVIF_PARAM;
lvi.iItem = item_index;

if(ListView_GetItem(hw, &lvi))
{
  // Call was sucessful, now you can use lvi.lParam

Quote:
}
>All I have is the index of the selected item based on the DISPLAY order.

Which is enough.

HTH or I hope it was what you were looking for.

Jimbo



Wed, 03 Dec 2003 20:00:00 GMT  
 REALLY annoying listview problem

Quote:
>When I handle the OK click, I use ListView_FindNextItem to get the index of
>the selected item.

The normal way of associating data with the items of a list control is
to store some appropriate identifier (or a pointer to the data) in the
item's lParam value of the LVITEM structure.

Dave Lowndes
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Wed, 03 Dec 2003 20:37:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. REALLY annoying listview problem

2. Really annoying VC7 compiler bug

3. Really annoying Beep

4. Question on Visual Studio- This annoying problem!!

5. An annoying problem...

6. annoying fgets problem <fgets>

7. annoying gcc problem

8. annoying ascii problem (dos/win specific)

9. Annoying Jet 3.5 OLE DB deployment problems

10. annoying linker problem

11. annoying DLL locating problem

12. Very annoying problem -- PLEASE HELP !!!

 

 
Powered by phpBB® Forum Software