Format Data Bound Textboxes as Currency
Recently, I ran into an issue where a customer wanted to display currencies in data bound textboxes, but there didn’t seem to be an easy way to do this. Luckily, I found the information in the MSDN forums and I figured I would create a simple project to bring together a bunch of threads on the subject. Here is the source code - Source Code .
So assuming you already have bound textboxes, here are three approaches I have found to deal with this issue.
1. Set the bindings through code In this case you set up the binding through code and now you need to modify it to display the data as a currency. Here is the code I used:
‘Formatting codes found at MSDN - Standard Numeric Format Strings http://msdn.microsoft.com/en-us/library/aa720653.aspx
Me.TextBox4.DataBindings.Add(“text”, PriceBindingSource, “Price”, True, DataSourceUpdateMode.OnPropertyChanged, ” “, “C”)
2. Format the field during an event I used the textchanged event, but how you do this is really based on the behavior you want.
Private Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.TextChangedMe.TextBox2.Text = FormatCurrency(Me.TextBox2.Text, 2)End Sub
3. Use Visual Studio Wizard Finally, you can use the Visual Studio IDE to set the bindings. What you need to do is select the textbox and expand the (DataBindings) property. Select the Advanced Binding field and then click on the button that appears in the field. A window will pop up and from there you can set the formatting for the textbox.

Hopefully this tidbit helps