I have created a currency textbox formatting with the _Validating event. I use this formatting for six textboxes that have to have their values added. So what happens is after I typed in an amount and left the textbox, the amount (the text I inputted) becomes formatted, and the 'Total' (where the sum is displayed) is automatically updated (I did this using the _TextChanged Event).
For example, I have inputted '2000', '3746.5', '890' and '567.34'. After I leave each textbox where I typed in those values, they become '2,000.00', '3,746.50', '890.00', and '567.34'. The 'Total' displays '7,203.84'. I have no problem with this, but I do have a problem when it comes to viewing of records.
Whenever I try to view a previously saved record, the six textboxes get filled up with values (based from what was saved in the record) but they don't automatically sum up ('Total' displays the last inputted text and not the sum of the current values in the six textboxes). I still have to make changes to any one of those six textboxes for the addition to happen (for the 'Total' to update).
I know that maybe this is because of the _Validating event (the event 'validates' the text in the textbox first) but what I want is for the addition to fire up instantly on record-viewing.
What can be done about this?
By the way, here are the codes that I used:
'this is the validating event Private Sub txtAmount2_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtAmount2.Validating Dim LenStr As String = Len(txtAmount2.Text) Dim RawString As String LenStr = LenStr - 4 If InStr(1, txtAmount2.Text, "PHP") <> 0 Then RawString = Microsoft.VisualBasic.Right(txtAmount2.Text, LenStr) RawString = RawString.Replace(",", "") Else If Double.TryParse(txtAmount2.Text, vbNull) Then amount2 = txtAmount2.Text txtAmount2.Text = FormatNumber(txtAmount2.Text, 2, TriState.False, , TriState.True) 'TextBox1.Text = "PHP " + TextBox1.Text txtAmount2.BackColor = Color.White Else txtAmount2.BackColor = Color.DarkOrange 'I removed e.Cancel = True because what if I accidentally 'tab-focused' on a textbox but didn't want to input anything? 'e.Cancel = True End If End If End Sub 'and this is what I call the 'addition' event Private Sub txtAmount2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAmount2.TextChanged Dim a As Double a = Val(amount1) + Val(amount2) + Val(amount3) + Val(amount4) + Val(amount5) totalu = a TextBox1.Text = Format(Val(a), "#,##0.00") End Sub