SIGN UP MEMBER LOGIN:    
ARTICLE

Filtered TextBox in Silverlight 3

Posted by Diptimaya Patra Articles | Silverlight with C# November 11, 2009
In this article we will see how we can filter a Textbox on Keyboard inputs.
Reader Level:
Download Files:
 

Introduction

In this article we will see how we can filter a Textbox on Keyboard inputs. We will see how we can block Numeric input from Keyboard.

Creating Silverlight Project

Fire up Visual Studio 2008 and create a new Silverlight 3 Project. Name it as FilteredTextBox.

1.gif

Add a TextBox to the Application.

Our aim is to block the Numerical key inputs, so have a event handler for KeyDown for the TextBox and add the following code in place.

private
void txtNumericFiltered_KeyDown(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:

            e.Handled = true;

            break;

        default:

            break;

    }

}

That's it. Run your application to test it.

If you press any numeric value and special characters associated with it won't be typed. Anything else is allowed.

Hope this article helps.

Login to add your contents and source code to this article
share this article :
post comment
 

you can still paste the number from the clipboard or use numeric keys from the right side of the keyboard. Not a very reliable implementation.

Posted by kilativ Nov 27, 2009
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor