Preformat data before loading into textbox?

General Fear

Member
Joined
Dec 22, 2012
Messages
12
Programming Experience
10+
I am using VB.Net 2010.

This is the problem. I have data in an Oracle database. The numbers in Oracle are not in currency format. They a straight up numbers. No dollar signs or commas. When I load it into a textbox, I want the data to be converted into a currency format. Here is the problem:

1.) Data binding is out. I am creating custom controls. These controls need to be generic so we can use in different applications.

2.) Textchanged event not working. The problem with textchange is that it works on every key stroke. Sure, when I first load the data it works, but then I get problems when typing.

I need the textbox to respond to an outside force like textbox1.text = 123.45.

So what can be done? Is there a way of coding "not while keypress" so the textchanged event only fires when the end user is not typing?
 
Probably your best option is to handle the Enter event and, depending on the behaviour you want, either the Leave event or the Validating and Validated events. You would remove all formatting while the control has focus, allowing the user to enter whatever they want. When the control loses focus, you then apply the appropriate formatting. If you want to enforce only valid numbers in the control then you would handle Validating to perform the validation and Validated to apply the formatting, otherwise you would handle Leave and apply formatting only if the data is valid.

I've actually already created a custom control that does all that and more. You're welcome to use it if you want.

Numeric Text Box
 
Back
Top