Problems with ListView and ListView_FindItem
Posted: Wed Jan 05, 2005 5:20 pm
I have a ListView Control, with 3 columns. I want to able to press a key and have the first item that starts with the given letter selected. the problem is, ListView_FindItem is always returning zero. what I am doing wrong?
Code: Select all
case LVN_KEYDOWN:
{
NMLVKEYDOWN* keyDown = (LPNMLVKEYDOWN) lParam;
if(keyDown->wVKey >= 0x41 && keyDown->wVKey <= 0x5a)
{
LVFINDINFO lvfi;
ZeroMemory(&lvfi, sizeof(LVFINDINFO));
TCHAR searchTerm[2];
sprintf(searchTerm,"%c",keyDown->wVKey);
lvfi.flags = LVFI_PARTIAL|LVFI_STRING;
lvfi.psz = searchTerm;
int idx=ListView_FindItem(GetDlgItem(hDlg,IDC_ROMLIST), -1, &lvfi);
ListView_SetSelectionMark(GetDlgItem(hDlg,IDC_ROMLIST), idx);
ListView_SetItemState(GetDlgItem(hDlg,IDC_ROMLIST), idx, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);
ListView_EnsureVisible(GetDlgItem(hDlg,IDC_ROMLIST), idx, FALSE);
}
break;
}