Solved

example of GetListCtrl()

Posted on 1998-11-13
6
861 Views
Last Modified: 2013-11-20
Could someone please provide an example of using GetListCtrl()?
0
Comment
Question by:jerryross
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1324651
This code is from a member function of a class derived from CListView:

 CListCtrl& ctrl = GetListCtrl();
 int count = ctrl.GetItemCount();
 for (int i = 0; i < count; i++)
 {
   // do something with each item
 }


0
 

Author Comment

by:jerryross
ID: 1324652
That makes sense, but my goal is to call FindItem for a ListView control.  I created the ListView control as a dialog resource, and now I want to search the control.  The I'm trying to call FindItem from code outside of the listview control.  Here is the code:

  CListView* pLB = (CListView*) GetDlgItem(IDC_LISTVIEW);
  CListCtrl *pLC;
  pLC = &(pLB->GetListCtrl());

  nIndex = ListView_FindItem( pLC->m_hWnd,-1,&plvfi);

Can you see a problem with the above?  FindItem returns with -1 every time even when it should match.
0
 
LVL 1

Accepted Solution

by:
atari earned 100 total points
ID: 1324653
CListView in a dialog ? There must be something wrong, you can only have a CListCtrl in a dialog box, and then what you only need to do is to define a member variable with class wizard as control for it. Then you could call:

LV_FINDINFO lvfi;
lvfi.flags = LVFI_STRING;      // Search strings
int index = m_YourListCtrl.FindItem(&lvfi, -1);

That's it,
bye,
atari
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 

Author Comment

by:jerryross
ID: 1324654
I had renamed the dialog and this prevented class wizard from showing new IDCs so I coudn't add a member variable for the list control.  I have done that, the next step is to figure out why FindItem doesn't work when i'm trying to search subItems.

Thanks,
Jerry
0
 
LVL 1

Expert Comment

by:atari
ID: 1324655
If you change something, that class wizard don't recognize then simply delete the .clw-file in your project folder and from within Visual C++ type Ctrl+W and let the class wizard build the .clw-file again. That's what one often had to do when including new files to the project or if some changes in the resource-file will be made that class wizard don't recognize.

Thanks,
bye,
atari
0
 

Author Comment

by:jerryross
ID: 1324656
Thank you!! That is very useful information.  

I didn't get FindItem to work so I just used the member variable created with class wizard to call GetText.  I just iterate through the list control comparing each subItem.  I'm sure this method is not as fast as FindItem, but it works.  Thank you for your help!

Jerry
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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
bobThere java chalenge 45 94
wait notify demo infinite loop 3 124
abstract class with all non abstract mentods 6 80
Problem to open Excel file 15 179
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

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