Victor Charles
asked on
Help with controlling characters entered in a combo box of a Windows application.
Hi,
I'm using the cmbobox that comes with VS2010. How do you only allow users to only numbers 0 -9 and symbos "/" and "-" in the combobox using vb.net?
Victor
I'm using the cmbobox that comes with VS2010. How do you only allow users to only numbers 0 -9 and symbos "/" and "-" in the combobox using vb.net?
Victor
hi ...Can you clarify a little bit more.In ComboBoxes we have a list of Values and we choose one of them...you need to filter these choises while typing only numbers 0 -9 and symbos "/" and "-" ?
ASKER
Yes that is correct, forgot to mention letters A-Z are also allowed.
take a look at this
https://www.experts-exchange.com/questions/20866840/Allow-only-letter-number-or-backspace-in-textbox-vb-net.html
https://www.experts-exchange.com/questions/20866840/Allow-only-letter-number-or-backspace-in-textbox-vb-net.html
Private Sub ComboBox1_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
e.Handled = Not (Char.IsDigit(e.KeyChar) Or e.KeyChar = "." Or Char.IsLetter(e.KeyChar) Or e.KeyChar = "-")
End Sub
ASKER
Thanks for the code, need to leave office for about two hours, will get back to you later.
Note that the above code does not restrict the Left Right Directional Keys..
If you want to Restrict these Keys Also Use The Key Down Event like:
If you want to Restrict these Keys Also Use The Key Down Event like:
If e.KeyCode = Keys.Left Then
e.SuppressKeyPress = True
End If
ASKER
Hi,
The code works but I am unable to remove data, back space does not work. Also when I include the second part of your in the key press event. I receive the following error:
keycode is not a member of system.Windows.Forms.KeyPr essEventAr gs, Í receive the same error message for SupressKeyPress.
Thanks,
V.
The code works but I am unable to remove data, back space does not work. Also when I include the second part of your in the key press event. I receive the following error:
keycode is not a member of system.Windows.Forms.KeyPr
Thanks,
V.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
It works!
Thank You.
Victor
Thank You.
Victor
glad i help you Victor...
ASKER
I appreciate your Help.