?
Solved

Problem with FindItem in CListView

Posted on 1997-09-29
2
Medium Priority
?
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.
Suggested Courses

718 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