HOW TO MAKE A TEXTBOX WHICH IS ONLY ACCEPT THE NUMERIC VALUE IN WPF

C G E Mannerheim

Total Post:29

Points:203
Posted by  C G E Mannerheim
WPF 
WPF
 2046  View(s)
Ratings:
Rate this:

Hello Mindstick!

I need to make a textbox in wpf application which is accept only numeric value.

thanks in advance

  1. shreesh chandra shukla

    Post:105

    Points:735
    Re: How to make a textbox which is only accept the numeric value in WPF

    Hi !

    try this

    private void myTextBox_PreviewKeyDown(object sender, KeyEventArgs e)

            {

                switch (e.Key)

                {

                    case Key.D0:

                    case Key.D1:

                    case Key.D2:

                    case Key.D3:

                    case Key.D4:

                    case Key.D5:

                    case Key.D6:

                    case Key.D7:

                    case Key.D8:

                    case Key.D9:

                    case Key.NumLock:

                    case Key.NumPad0:

                    case Key.NumPad1:

                    case Key.NumPad2:

                    case Key.NumPad3:

                    case Key.NumPad4:

                    case Key.NumPad5:

                    case Key.NumPad6:

                    case Key.NumPad7:

                    case Key.NumPad8:

                    case Key.NumPad9:

                    case Key.Back:

                        break;

                    default:

                        e.Handled = true;

                        break;

                }

            }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!