none
thousand separator in TextChanged textbox c#

    Question

  • hello guys 

    i want to when  enter an int number like 12345 to the textbox becom like 12,345 in TextChanged  event

    pls help tnx ;

    Tuesday, April 18, 2017 7:45 PM

Answers

  • Hi arman_gorjipoor,

    Thank you for posting here.

    For your question, please try the following code.

      private void textBox5_TextChanged(object sender, EventArgs e)
            {       
                if (!string.IsNullOrEmpty(textBox5.Text))
                {
                    System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
                    int valueBefore = Int32.Parse(textBox5.Text, System.Globalization.NumberStyles.AllowThousands);
                    textBox5.Text = String.Format(culture, "{0:N0}", valueBefore);
                    textBox5.Select(textBox5.Text.Length, 0);
                }
            }

    I hope this would be helpful.

    Best Regards,

    Wendy


    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, April 19, 2017 6:35 AM
    Moderator

All replies

  • Hi!

    You'll find the answer in this link : https://www.codeproject.com/Tips/594117/Textbox-for-numbers-with-a-comm

    Hope it wil be useful.

    If it's good for you, can you mark this answer as answer of your question please?

    Follow me on twitter : https://twitter.com/NordineMhoumadi


    Download my NEW FREE application MCP PREPARATION in the Windows 10 Store for preparing your Microsoft Certification or test your skills in Microsoft Technologies;

    Tuesday, April 18, 2017 7:59 PM
  • Hi arman_gorjipoor,

    Thank you for posting here.

    For your question, please try the following code.

      private void textBox5_TextChanged(object sender, EventArgs e)
            {       
                if (!string.IsNullOrEmpty(textBox5.Text))
                {
                    System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
                    int valueBefore = Int32.Parse(textBox5.Text, System.Globalization.NumberStyles.AllowThousands);
                    textBox5.Text = String.Format(culture, "{0:N0}", valueBefore);
                    textBox5.Select(textBox5.Text.Length, 0);
                }
            }

    I hope this would be helpful.

    Best Regards,

    Wendy


    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, April 19, 2017 6:35 AM
    Moderator