For all coding issues - MODers and programmers, HTML and more.
Moderators: Jeff250 , fliptw
fliptw
DBB DemiGod
Posts: 6459 Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada
Post
by fliptw » 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;
}
Nirvana
DBB Harasser
Posts: 1123 Joined: Thu Nov 05, 1998 12:01 pm
Contact:
Post
by Nirvana » Thu Jan 06, 2005 4:38 am
0 would be the first index... if the first index had the character pressed, it would find that one... are you sure it's not a user error?
fliptw
DBB DemiGod
Posts: 6459 Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada
Post
by fliptw » Thu Jan 06, 2005 2:45 pm
my understanding of LVFI_PARTIAL is that it matches the start of the string, so If I press A, it'll match the first item that starts with A, and so on.
it returns 0 even if the letter doesn't exist in any of the items.
this listview control is displaying contents of a given folder.
DCrazy
DBB Alumni
Posts: 8826 Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle
Post
by DCrazy » Thu Jan 06, 2005 5:57 pm
Try including LVFI_WRAP so that typing works from anywhere in the list.
fliptw
DBB DemiGod
Posts: 6459 Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada
Post
by fliptw » Fri Jan 07, 2005 1:11 am
Sure, leave to MS not to tell you one needs to process the LVN_ODFINDITEM notification.
ListView can't search anything by itself.
DCrazy
DBB Alumni
Posts: 8826 Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle
Post
by DCrazy » Fri Jan 07, 2005 9:15 am
It actually makes sense, because no common controls ever do anything on their own... it's always up to us to re-implement the same basic functionality.
fliptw
DBB DemiGod
Posts: 6459 Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada
Post
by fliptw » Fri Jan 07, 2005 3:04 pm
the funny thing is, this listview worked properly a year ago.
no LVN_ODFINDITEM anywhere in the code.