Results 1 to 4 of 4

Thread: [RESOLVED] Numeric Textbox with "backspace"

  1. #1

    Thread Starter
    Banned
    Join Date
    Aug 2009
    Posts
    333

    Resolved [RESOLVED] Numeric Textbox with "backspace"

    Im using
    Code:
     Private Sub NumericKeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
            Dim allowedChars As String = "0123456789"
    
            If allowedChars.IndexOf(e.KeyChar) = -1 Then
                e.Handled = True
            End If
    
        End Sub
    and it wont let me use backspace. How would I make it so I can use backspace?

  2. #2
    Lively Member
    Join Date
    Sep 2009
    Location
    Florida
    Posts
    75

    Re: Numeric Textbox with "backspace"

    Take a look at the list of characters you've allowed ... and be aware that the backspace is simply another character.
    "The most important quality a programmer must have is persistence."

  3. #3

    Thread Starter
    Banned
    Join Date
    Aug 2009
    Posts
    333

    Re: Numeric Textbox with "backspace"

    Quote Originally Posted by OldProgrammer View Post
    Take a look at the list of characters you've allowed ... and be aware that the backspace is simply another character.
    What would be the Backspace though?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Numeric Textbox with "backspace"

    Forget testing against an array:
    vb.net Code:
    1. e.Handled = Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar)
    IsControl accounts for baskspace, delete and others.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width