Solved

Problem with FindItem in CListView

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 73
FMX enumerated colours 2 118
Where are the c++ header files to use in Eclipse? 4 24
FMX TEdit KeyUp handler detecting  "enter" key 4 14
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…
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 …
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

830 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