Re: problem iterating over list view items
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Mon, 28 Nov 2005 16:03:34 -0500
Steve <sss@xxxxxxx> wrote:
> Using this code:
> <code>
> LVITEM item;
> item.mask = /*LVIF_STATE|*/LVIF_TEXT;
> HWND hList = GetDlgItem(hDlg, IDC_LIST_CHARACTERS);
> int n = ListView_GetItemCount(hList);
> while(ListView_GetItem(hList, &item) == TRUE)
> {
> if(item.state&LVIS_SELECTED)
> {
> // this item is selected
> int y = 5;
> }
> }
> </code>
>
> I am trying to determine if an item is selected. Before I can even
> get that far, I need to get the code that loops through the items to
> work.
> my call(debugging) to ListView_GetItemCount() return 2
> I am inserting/setting the items with the LVIF_TEXT flag.
>
> ListView_GetItem() macro returns FALSE. I've set the correct mask
> (LVIF_TEXT) so I don't understand why it's not getting valid results?
You need to set LVITEM::iItem to the index of the item you are trying to
retrieve, and iSubItem to zero (unless you actually want to retrieve a
subitem). Further, since you are requesting the text of the item, you
need to have pszText point to a buffer and cchTextMax specify the size
of this buffer in characters. Further still, since you have not
requested LVIF_STATE, you have no business checking item.state field -
it was not retrieved and contains garbage.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- Follow-Ups:
- Re: problem iterating over list view items
- From: Steve
- Re: problem iterating over list view items
- References:
- problem iterating over list view items
- From: Steve
- problem iterating over list view items
- Prev by Date: problem iterating over list view items
- Next by Date: Re: problem iterating over list view items
- Previous by thread: problem iterating over list view items
- Next by thread: Re: problem iterating over list view items
- Index(es):
Relevant Pages
|
Loading