none
Question about The "," custom specifier ?! RRS feed

  • Question

  • I checked this link out to see if it converts my textbox's digits into 3-digit-group format

    It works fine when I use a button to do the trick. But what If i want it to lively group digits while typing ?

    I tested the code putting it under textbox1.textchanged, but it reverses the whole number, the more you type digits in. Another problem using the code in this case is when I try to use backspace key removing some digits.

    any solution ?

    Wednesday, March 6, 2019 8:23 AM

Answers

  • Hi,

    code:

      Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    
            RemoveHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
            Dim t = CDbl(TextBox1.Text)
            TextBox1.Text = t.ToString("#,#", CultureInfo.InvariantCulture)
            AddHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
            TextBox1.Select(TextBox1.TextLength, 0)
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Kevin993 Wednesday, March 6, 2019 9:32 AM
    Wednesday, March 6, 2019 9:07 AM

All replies

  • Hi,

    code:

      Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    
            RemoveHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
            Dim t = CDbl(TextBox1.Text)
            TextBox1.Text = t.ToString("#,#", CultureInfo.InvariantCulture)
            AddHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
            TextBox1.Select(TextBox1.TextLength, 0)
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Kevin993 Wednesday, March 6, 2019 9:32 AM
    Wednesday, March 6, 2019 9:07 AM
  • Hi,

    code:

      Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    
            RemoveHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
            Dim t = CDbl(TextBox1.Text)
            TextBox1.Text = t.ToString("#,#", CultureInfo.InvariantCulture)
            AddHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
            TextBox1.Select(TextBox1.TextLength, 0)
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Bravo!

    My last question is :

    How to change it back to a normal string of digits without any "," ?

    I tested the replace method, didn't work

    Wednesday, March 6, 2019 9:19 AM
  • Hi,

    try the code:

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            RemoveHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
            TextBox1.Text = TextBox1.Text.Replace(",", "")
            AddHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
    
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 6, 2019 9:29 AM