WPF - Build a string of pressed keys using KeyDown in ListView -
i have listview dozen of rows binded xml. i'd have possibility locate , position cursor record. example: have these id, name, value:
1, johny, cash, usa 2, jean-michel, jarre, france 3, jeanette, , usa
when type "je", selectedrow positioned id 2. when type "jeane", selectedrow positioned id 3. i'd have possibility search , go proper record in listview. started building searchstring , @ point got stuck:
the 1 , possibility in wpf use keydown event. unfortunately, event return kind of key, not able convert string. e.g. when press "a", searchstring "a". when continue typing "b", searchstring "ab" etc. when selecteditem changes, searchstring set string.empty. no keycode or other useful property/method available.
and here comes head rubbing. how can build searchstring need? when tried e.key.tostring(), got funny strings - e.g. 0 on numpad key "numpad0", "," "oemcomma" etc. trying tryparse method char, key "3" value of "#" etc, works flawlessly letter through z, other keys tryparse returns false.
the 1 , way how solve build translation table long kind of "case e.key.tostring() of":
"a": searchstring = searchstring + "a"; "system", searchstring = searchstring + " "; "numpad0", searchstring = searchstring + "0"; "arrowup", nothing
etc etc etc.
isn't there more clever , simple way this?? or don't see trees because of forest?
handle previewtextinput instead. reference: http://social.msdn.microsoft.com/forums/en-us/wpf/thread/3fcfbe53-2c72-4fec-a997-dc881d1de72a.
edit:
note: listview (and listbox also) internally handles keydown event keys perform selection , navigation. below keys internally handled listview:
key.space: key.return: key.prior: key.next: key.end: key.home: key.left: key.up: key.right: key.down:
key.space of particular interest because when space pressed on listview, previewtextinput event not fired. complete solution, have add handler listview.previewkeydown event , check if space key pressed in order append correct whitespace text.
Comments
Post a Comment