-
November 9th, 2013, 01:34 AM
#1
Item search in Listview control
Hi,In my win32 application i have a list view control with grid view style ,i want to search items/SubItem on this List view control.I used ListView_FindItem macro,But it always returning 0 for both item as well as subitem.How to find out an item or subitem string from a list view control
Code:
UINT uFindReplaceMsg;
BOOL CALLBACK SymbolNCommntDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND HdlgFindOrReplce = NULL; // handle to Find dialog box
switch (message)
{
case WM_INITDIALOG:
{
ListView_SetExtendedListViewStyle(hWndListViewSymbol,LVS_EX_GRIDLINES| LVS_EX_FULLROWSELECT );
}
break;
case WM_NOTIFY:
{
switch(LOWORD(wParam))
{
case IDC_LIST1:
{
switch(((LPNMHDR) lParam)->code)
{
case LVN_KEYDOWN :
{
NMLVKEYDOWN * pnkd = (LPNMLVKEYDOWN) lParam;
//CNTRL+F Find Dialog Box created
if(pnkd->wVKey=='F' || pnkd->wVKey=='f')
{
if(GetKeyState(0x11)<0)
{
static FINDREPLACE Find; // common dialog box structure
static WCHAR szFindWhat[100]; // buffer receiving string
// Initialize FINDREPLACE ZeroMemory(&Find, sizeof(Find));
Find.lStructSize = sizeof(Find);
Find.hwndOwner = hWnd;
Find.lpstrFindWhat = szFindWhat;
Find.wFindWhatLen = _countof(szFindWhat);
Find.Flags =FR_HIDEUPDOWN|FR_HIDEMATCHCASE|FR_HIDEWHOLEWORD ;
HdlgFindOrReplce = FindText(&Find);
}
}
}
break;
default:
{
LPFINDREPLACE lpfr;
if (message == uFindReplaceMsg)
{
if (lpfr->Flags & FR_DIALOGTERM)
{
HdlgFindOrReplce = NULL;
return 0;
}
//If FindNext clicked searcching for the item in list view and make //it selected
if ((lpfr->Flags & FR_FINDNEXT))
{
int i;
LVFINDINFO plvfi={0};
plvfi.flags=LVFI_STRING;
plvfi.psz=lpfr->lpstrFindWhat;
i=ListView_FindItem(hWnd,-1,&plvfi);//returning 0 for any item
DWORD dw=GetLastError();//Returning 0
ListView_SetItemState(hWnd,i,LVIS_FOCUSED|LVIS_SELECTED,0x000F);//For selcting that item
}
else
return DefFrameProc(hWnd, hWndListViewSymbol,message, wParam, lParam);
}
}
}
}
break;
}
}
break;
default:
return FALSE;
}
return TRUE;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|