Disable ListBox (Default) Keypress Navigation

JumpyNET

Centurion
Joined
Apr 4, 2005
Messages
196
I have a ListBox with a list of files in it. When a user presses the letter "a", then it goes to the first file that starts with the letter "a". When a user presses the next letter "s", then it goes to the first file that starts with the letter "s". Etc.

I want to disable the default keypress navigation for the ListBox, and perform my own navigation, so instead of the ListBox doing what I described above, it will search as follows: When a user presses the letter "a", then it goes to the first file that starts with the letter "a". When a user presses the next letter "s", then it goes to the first file that starts with the letter "as". Etc.

I ALREADY have code that accomplishes this. However, when a user presses a letter, then the ListBox performs it's default navigation first, and then moves to the one I selected. It looks really sloppy.

My question is, How can I disable the (Default) KeyPress Navigation of the ListBox so it will not occur at all, and only my navigational code will be used?

Suppressing the KeyPress in KeyDown event won't help because then I can't access the KeyChar wich only seems to be in the KeyPress event. I also tried to convert KeyCode to KeyChar in the KeyDown event but it doesn't work properly.
 
Finding the solution took some "crazy" experimenting.

The KeyDown event can be suppressed by...
Code:
e.SuppressKeyPress = True
...but there is no such thing in the KeyPress event.

Instead the KeyPress event can be suppressed by...
Code:
e.KeyChar = Nothing
...after wich the ListBox's Keypress Navigation will not function. :)
 
Back
Top