Link to home
Start Free TrialLog in
Avatar of mromeo
mromeo

asked on

Using FindItem to find a string in any column of CListCtrl

I have a CListCtrl with three columns.  I want to use the FindItem method to find a string in any of the 3 columns of the ctrl.  It looksl iike I'm supposed to use the lParam field of the LVFINDINFO struct, but it's not obvious to me how to use this technique.  Anybody have any ideas?

Thanks.
Avatar of _corey_
_corey_

No, you just need to use the LVFINDINFO structure and tell it to search for a string, or partial and string if you want stuff like beginning matches.

In this example replace the line:
info.psz = lpszmyString

with your string assignment.  The string you want to search for.

-- Taken from Microsoft examples for consistancy.
// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
// The string to match.
extern LPCTSTR lpszmyString;

LVFINDINFO info;
int nIndex;

info.flags = LVFI_PARTIAL|LVFI_STRING;
info.psz = lpszmyString;

// Delete all of the items that begin with the string lpszmyString.
while ((nIndex=pmyListCtrl->FindItem(&info)) != -1)
{
   pmyListCtrl->DeleteItem(nIndex);
}
Avatar of mromeo

ASKER

This only searches on the first column in the list control.  I have 3 columns and I want to be able to search for text in all 3 of them.   Is this possible?
ASKER CERTIFIED SOLUTION
Avatar of _corey_
_corey_

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 do not know what VK_HOME would do.  Or VK_NEXT.