Connecting Tech Pros Worldwide Forums | Help | Site Map

Show Currency

Member
 
Join Date: Nov 2007
Posts: 125
#1: Nov 1 '08
hello,

i have a textbox for product price that the user will be able to enter some number and also a column in a datagridview to show the same price too,

is it possible to show the thousands separator as a user types in. like when a user types 1000, it will be shown as 1,000. and if it possible, when i get the value in the textbox, can i convert it to an integer?

thank you
kspiros's Avatar
Newbie
 
Join Date: Oct 2008
Posts: 16
#2: Nov 1 '08

re: Show Currency


In order to convert a value to an integer you can do two things
you can use this
Expand|Select|Wrap|Line Numbers
  1. X=Convert.ToInt32(textBox.Text);
or this
Expand|Select|Wrap|Line Numbers
  1. X=Int32.Parse(textBox.Text) ;
joedeene's Avatar
Site Addict
 
Join Date: Jul 2008
Location: US of A
Posts: 587
#3: Nov 1 '08

re: Show Currency


You can do something like this for the thousandths place...

Expand|Select|Wrap|Line Numbers
  1. private void textBox1_TextChanged(object sender, EventArgs e)
  2.         {
  3.             if (textBox1.TextLength == 4)
  4.             {
  5.                 textBox1.Text = textBox1.Text.Insert(1, ",");
  6.  
  7.             }
  8.  
  9.         }
But after it inserts the text it brings the cursor to the beginning of the textbox. :( Why not have a button and parse the text and then you can convert it to an integer within that function too.

joedeene
Reply