c# - Use Up/Down keys to scroll a ListBox when a TextBox has focus without moving cursor -
i have textbox
user can type search term , listbox
displays results. there button display information based on item selected on click.
i'm trying scroll through listbox using , down arrow keys user doesn't have click item, button. @ point might rely on double click event work since on item. however, i'm trying make more "keyboard friendly".
following code works, 1 minor flaw:
private void txtsearchterm_keydown(object sender, keyeventargs e) { if (e.keycode == keys.down && results.selectedindex < (results.items.count - 1)) { results.selectedindex++; } else if (e.keycode == keys.up && results.selectedindex > 0) { results.selectedindex--; } }
with code, cursor still moves left , right along selected item changing. want remain (not forcing end). didn't have luck txtsearchterm.select(...)
event, guess have missed something...
there textchanged
event, calls search function wrote populates list box user types, leave code out simplicity.
am missing or overlooking method make textbox/listbox combo function how i'm intending?
quick note: if you've ever used ultraedit, i'm trying mimic behavior of configuration window, basically.
you should use e.handled = true;
cancel using key processed:
private void txtsearchterm_keydown(object sender, keyeventargs e) { if (e.keycode == keys.down) { if (results.selectedindex < (results.items.count - 1)) results.selectedindex++; e.handled = true; } else if (e.keycode == keys.up) { if (results.selectedindex > 0) results.selectedindex--; e.handled = true; } }
i set e.handled = true;
if key keys.down
or keys.up
regardless of selectedindex
disable moving caret using keys.
Comments
Post a Comment