problem with combo box

thiya

New member
Joined
Apr 22, 2005
Messages
3
Programming Experience
1-3
HI ALL:

In my application, I need to restrict the user to enter the keyboard input to the combo box.

when i was working in vb6 i had used the code:

keyascii=0 in keypress event of combo box

How can i acheive for vb.net combo box

thanks in advance
 
You will probably want to use Char.IsLetter() in the KeyDown event handler. You may also want to test for the Ctrl and Alt keys, which you can do with the KeyEventArgs parameter passed to the KeyPress event handler. Something like:
VB.NET:
Dim ctrlDown as Boolean 'Whether the Ctrl key was depressed.
Dim altDown as Boolean 'Whether the Alt key was depressed.

Private Sub textBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles textBox1.KeyDown
  'Note whether the Ctrl or Alt key were depressed.
  ctrlDown = e.Control
  altDown = e.Alt
End Sub

Private Sub textBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles textBox1.KeyPress
  If Not Char.IsLetter(e.KeyChar) OrElse ctrlDown OrElse altDown
	'Prevent the key press being processed.
	e.Handled = True
  End If
End Sub
 
Last edited:
Back
Top