Click here to Skip to main content
15,877,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
we have some requirement like:
Default values should be displayed as 0.00 in the textbox.
And here some criteria like before decimal, it should accept <=13 digits and after decimal it should accept only 2 digits and "." should be readonly.User should not able to remove "."
If user enter the value like "1234567890123.12" then i want to display the format "1,234,567,890,123.12".
Ex:12345.56
output:12,345.56
Posted
Updated 8-Jun-10 2:13am
v2
Comments
Tom Deketelaere 8-Jun-10 8:14am    
And your question is?
You'll have to write a custom control for this (isn't that hard to do)
You don't expect us to just write if for you now do you, don't you want to learn something?
Show us what you have tried and where you are stuck (specific piece of code if possible) and we'll help but we won't just write this for you.

Have a look at Masked Text Box[^] it should do what you want, but you may have to fiddle with the mask a bit...
 
Share this answer
 
Comments
Tom Deketelaere 8-Jun-10 9:01am    
It won't do everything he want's but it will get close.
NareshNama 9-Jun-10 7:44am    
masked text box is a fixed length.Through this is not possible.
Ex:For 13 digits value,if i enter only 10 digits it will display like
msked text box = 1234567890___.56(in design time)
As Tom has already suggested a Custom Control would probably be the most efficient way to meet your requirements.

To help you in the design you should research String.Format() and FormatStrings.
 
Share this answer
 
You can set MaskEdit Control to meet your requirement and after entering value you can use format function to display with your desire output.

If you want to your textbox should accept either 13 or <13 character then you must use format function to satisfy your requirement.

User textbox validated event and check it.

Txt_validated()
if txt.text.length < 13 then
txt.text = format(txt.text,"#############.##")
end if
end sub


For getting details that only one decimal point should allowed and after that only 2 digits can be allowed for that you have to use key press event and with instr function you can check whether decimal point is there or not.
 
Share this answer
 
Comments
NareshNama 9-Jun-10 7:54am    
Ofcourse,this one will work.I am using the below code in leave event
txtQuantity.Text = Convert.ToDecimal(txtQuantity.Text).ToString("#,###,###,###,##0.00")
After moving into next text box the format will work and again am trying to remove "." and adding 1 more digit in txtQuantity textbox and if i press tab its showing total 14 digits(extra 1 digit added instead of dot) and 2 digits after decimal.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900