Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

Combobox KeyPress Event

Apr 15 2003 12:31 PM
I have been looking around the Internet in hopes to find a way to restrict certian keys from being accepeted from a combobox control... I found an article that explains using the KeyPress Event and setting the KeyPressEventArg.Handled property to true. I thought is was heaven until I tried it... On a combobox I could not get it to restrict the keystrokes but when I past the exact same code into a textbox's Keypress event it worked like a charm. N E IDEAS. The following will not restrict numeric values from being entered private void CombopBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( char.IsDigit ( e.KeyChar ) ) e.Handled = true; } the following does restrict numeric values from being entered private void TextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if ( char.IsDigit ( e.KeyChar ) ) e.Handled = true; } I don't get it? Jim Di Crescenzo

Answers (1)