Solved

Problem with FindItem in CListView

Posted on 1997-09-29
2
383 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

920 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