Solved

Problem with FindItem in CListView

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

734 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