Cannot exit textbox when blocking keys  
Author Message
CoreyMc





PostPosted: Windows Forms General, Cannot exit textbox when blocking keys Top

Using the keypress event, I am limiting the characters that can be entered into a textbox to numeric values, backspace, and the decimal key. Somehow my code to allow the decimal character (46) to be entered is preventing me from exiting the textbox when making edits containing a decimal in my application - focus is stuck on this textbox. However it does allow me to enter the decimal character as desired. When I comment the "ElseIf e.KeyChar = Chr(46)" lines out, the textbox behaves fine...but the decimal character is blocked. Any help is appreciated!

If IsNumeric(e.KeyChar) = True Then

e.Handled = False

ElseIf e.KeyChar = Chr(46) Then

e.Handled = False

ElseIf e.KeyChar = vbBack Then

e.Handled = False

Else

e.Handled = True

End If



Windows Forms31  
 
 
Peter Ritchie





PostPosted: Windows Forms General, Cannot exit textbox when blocking keys Top

Could you post the entire event handler code, we can't tell much from the code you posted.

 
 
CoreyMc





PostPosted: Windows Forms General, Cannot exit textbox when blocking keys Top

I figured the problem out. This text box is databound to a field that was incorrectly defined as integer type when decimal type was intended. That's why it didn't like the entered decimal point. Oops!