what the best way to format a textbox that is going to accept a price with a decimal: 11.99
Printable View
what the best way to format a textbox that is going to accept a price with a decimal: 11.99
accept only five chars(two digits on the left , dot , two digits on the right)
This is what I mean . Actually you have different techniques but this is an example .
Sorry forgot the important thing : attachment!:D
Another method may be to use the public event Validating - inherited from Control. Unlike Pirate's example, where you capture keystrokes (which is very cool and gives you lots of control), this event fires after you leave the control.
There's a good example in the help where this event is explained.
The demo I've uploaded can capture keys too that you don't need . That would prevent the user from typing more than 5 chars in textchanged event (which is more efficient way than validating after the user finishes typing ) .Can you tell more about things about that Mike Hildner;) .
Personally, I like capturing the key presses, because it gives you a lot of control. Whether it's more effecient or not, I don't know. I just wanted to mention another method. Always nice to have options.
Well , I know it's good , but this can exactly does the job as Validation (although the latter has some problems , and sometimes guys suffer from it ). ;)
If you want i can provide the backend code for a custom txtbox control that i wrote. This control provides you with the following validation options
decimal
currency (includes $ and pound signs)
numeral only
url
text only
anything goes
let me know if you would like to see how i achieved this
Not sure who you're asking, but I'd like you to post. I'm new to .NET and would like an example to study.
TIA,
Mike
okay well here is the code
pirate is there a way to only allow the user two spaces after they put in a decimal?
also, I have two textboxes that are going to accept prices. One is going to accept the Total and the other Sales Tax. I need to add these to values and store it into a variable. What do I declare the variable as? A double or a decimal?
The easiest way is : set Max Length of a textbox to 7 chars .Quote:
Originally posted by EyeTalion
pirate is there a way to only allow the user two spaces after they put in a decimal?
cool...thanks for all the help guys
forgot about this one ;)
The most suitable variable type for this case would be Decimal which can handle more digits on both sides of the decimal point .
Why don't you use any array instead of variables ?