Problems with ListView and ListView_FindItem

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6458
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Problems with ListView and ListView_FindItem

Post by fliptw »

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;
}
User avatar
Nirvana
DBB Harasser
DBB Harasser
Posts: 1123
Joined: Thu Nov 05, 1998 12:01 pm
Contact:

Post by Nirvana »

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?
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6458
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Post by fliptw »

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.
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post by DCrazy »

Try including LVFI_WRAP so that typing works from anywhere in the list.
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6458
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Post by fliptw »

Sure, leave to MS not to tell you one needs to process the LVN_ODFINDITEM notification.

ListView can't search anything by itself.
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post by DCrazy »

:roll: 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.
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6458
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Post by fliptw »

the funny thing is, this listview worked properly a year ago.

no LVN_ODFINDITEM anywhere in the code.
Post Reply