Thousand Seperator in TextBox
-
Hello Please help me to show thousand seperator in textbox like: 25000000>25,000,000 I found a formul like below at textchanged event:
string myStr = textBox1.Text; TextBox1.Text = myStr.FormatString("#,###");
But it causes error at :Int a = Convert.ToInt16(TextBox1.Text);
I want to seperate numbers in textbox anyway. I couldn't use "MaskedTextBox" Please help me. Regards -
Hello Please help me to show thousand seperator in textbox like: 25000000>25,000,000 I found a formul like below at textchanged event:
string myStr = textBox1.Text; TextBox1.Text = myStr.FormatString("#,###");
But it causes error at :Int a = Convert.ToInt16(TextBox1.Text);
I want to seperate numbers in textbox anyway. I couldn't use "MaskedTextBox" Please help me. Regards -
Hello Please help me to show thousand seperator in textbox like: 25000000>25,000,000 I found a formul like below at textchanged event:
string myStr = textBox1.Text; TextBox1.Text = myStr.FormatString("#,###");
But it causes error at :Int a = Convert.ToInt16(TextBox1.Text);
I want to seperate numbers in textbox anyway. I couldn't use "MaskedTextBox" Please help me. RegardsYou can replace FormatString with ToString("N0"). And there are at least two problems with your parsing code. First of all, you convert TextBox1.Text to a 16-bit integer, then store it as a 32-bit integer. This constrains it to the value 65,535. That's far too small for the value you want. Additionally, you're using Convert.ToInt16. Use the method int.Parse() instead.
Between the motion And the act Falls the Shadow
-
Hello Please help me to show thousand seperator in textbox like: 25000000>25,000,000 I found a formul like below at textchanged event:
string myStr = textBox1.Text; TextBox1.Text = myStr.FormatString("#,###");
But it causes error at :Int a = Convert.ToInt16(TextBox1.Text);
I want to seperate numbers in textbox anyway. I couldn't use "MaskedTextBox" Please help me. RegardsHi, you can tell Parse and TryParse what it is you want to allow, e.g.:
int val; bool OK=int.TryParse("12,345", NumberStyles.AllowThousands, null, out val);
:)
Luc Pattyn
:badger: :jig: :badger:
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
:jig: :badger: :jig:
-
Hi, you can tell Parse and TryParse what it is you want to allow, e.g.:
int val; bool OK=int.TryParse("12,345", NumberStyles.AllowThousands, null, out val);
:)
Luc Pattyn
:badger: :jig: :badger:
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
:jig: :badger: :jig:
Hello Tanks for your help. I used your code like below :
Int64 val; bool ok; ok = Int64.TryParse(TextBox1.Text, NumberStyles.AllowThousands, null, out val); TextBox1.Text = Convert.ToInt64(val.ToString()).ToString("#,###");
The problem accures after typing more than 4 numbers. Because cursor qoes to the left side of numbers, For example i want to type 12345, after typing 4 in typing 5 it TextBox shows : 51,234 Can you help me on this? Regards -
Hi, you can tell Parse and TryParse what it is you want to allow, e.g.:
int val; bool OK=int.TryParse("12,345", NumberStyles.AllowThousands, null, out val);
:)
Luc Pattyn
:badger: :jig: :badger:
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
:jig: :badger: :jig:
Hi again I solved it by below code:
TextBox1.Select(TextBox1.Text.Length, 0);
Bye -
Hello Tanks for your help. I used your code like below :
Int64 val; bool ok; ok = Int64.TryParse(TextBox1.Text, NumberStyles.AllowThousands, null, out val); TextBox1.Text = Convert.ToInt64(val.ToString()).ToString("#,###");
The problem accures after typing more than 4 numbers. Because cursor qoes to the left side of numbers, For example i want to type 12345, after typing 4 in typing 5 it TextBox shows : 51,234 Can you help me on this? Regardsuse this code: by this code,your problem is ok
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
string ss = textBox1.Text.Replace(",", "");
int d = int.Parse(ss);
string gg = String.Format("{0:###,###,###}", d);
textBox1.Text = gg;textBox1.SelectionStart = textBox1.Text.Length; } catch { } }
try { string ss = textBox1.Text.Replace(",", ""); int d = int.Parse(ss); string gg = String.Format("{0:###,###,###}", d); textBox1.Text = gg; textBox1.SelectionStart = textBox1.Text.Length; } catch { }