I have a code that binds the data from the database to textboxes. The problem is I want to make one of the textboxes Payment use a dollar sign.
I tried formatting it as shown in the code below but only the first record gets formatted, the rest do not. When I click the next button, the dollar sign disappeared.
Here is a portion of the code:
bs = New BindingSource(ds, ds.Tables(0).TableName)
Me.txtPayment.DataBindings.Add("Text", bs, "Payment")
Me.txtPayment.Text = Format(CType(txtPayment.Text, Decimal), ("c"))
I have tried everything else I know, FormatCurrency but no luck.
Payment is the name of the column in the database, the data type in SQL Server is
I would really appreciate any ideas!
The reason the above code did not work is because the code only fired once when the form load.
So the solution is to either change the code to this:
Me.txtPayment.DataBindings.Add("Text", bs, "Payment", True, DataSourceUpdateMode.OnPropertyChanged, 0, "c")
Or to place the below section of the code in the text change event, like this:
Private Sub txtPayment_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtPayment.TextChanged Me.txtPayment.Text = Format(CType(txtPayment.Text, Decimal), ("c")) End Sub
And that's it!