Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

Finding the solution took some "crazy" experimenting.

 

The KeyDown event can be suppressed by...

e.SuppressKeyPress = True

...but there is no such thing in the KeyPress event.

 

Instead the KeyPress event can be suppressed by...

e.KeyChar = Nothing

...after wich the ListBox's Keypress Navigation will not function. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...