Solved

Problem with FindItem in CListView

Posted on 1997-09-29
2
367 Views
Last Modified: 2012-08-13
I am trying to use the FindItem function to determine which item is currently selected but it seems to return -1 (error) no matter what information I enter. e.g.

      LV_FINDINFO      lvf;
      int nFound;
      lvf.flags = LVFI_PARAM;
      lvf.lParam = LVIS_SELECTED;
      CListCtrl& theCtrl = GetListCtrl();
      nFound = theCtrl.FindItem(&lvf,-1);

I've tried all the other lParam options to no avail. Anybody   know the answer?
0
Comment
Question by:cuppajava
2 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1170478
Unfortunately, the LV_FINDINFO does not work that way. The LVFI_PARAM will find the first item whose ItemData (which is set by SetItemData) is equal to LV_FINDINFO.lParam.

If you want to find the first or any items that is selected, you will need to use GetItemState() on each item and check if the LVIS_SELECTED flag is turned on.

  for (int i = 0; i < GetItemCount(); i++)
  {
    if (GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED)
    {
       // Item is selected
    }
  }


0
 

Author Comment

by:cuppajava
ID: 1170479
Thanks alot thui!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now