Solved

example of GetListCtrl()

Posted on 1998-11-13
6
845 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 158
dog bark java program 15 95
fizzArray2 challenge 1 79
scoreUp challenge 14 62
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

785 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