Solved

example of GetListCtrl()

Posted on 1998-11-13
6
812 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
List out all word 7 223
Window placement 17 64
Line meaning 9 76
how to split multiple lines delimiter : 8 53
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now