Link to home
Start Free TrialLog in
Avatar of jerryross
jerryross

asked on

example of GetListCtrl()

Could someone please provide an example of using GetListCtrl()?
Avatar of Tommy Hui
Tommy Hui

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
 }


Avatar of jerryross

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of atari
atari

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
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