Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1960
Limit allowed characters using the KeyDown event does not work as expected.
posted

Hello,

On the attached sample application I have some code in place to handle the KeyDown event and limit the characters the user can type to only allow hex characters (1 to 9 and A to F).

However at run time the grid lets me type any character, even though I'm cancelling the key calling KeyEventArgs.Handled = true inside the event handler.

What am I missing?

GridKeyDownSample.zip
Parents
  • 37774
    Suggested Answer
    posted

    It seems like KeyDown is the wrong event to use, even with the standalone .NET TextBox, since the key will still be processed.  The correct event to handle is the KeyPress event, though you'll have to modify your IsHexKey method to check for characters instead of a Keys value.

    -Matt

Reply Children
No Data