Textbox contents dissapear

base836ball

Active member
Joined
May 4, 2005
Messages
31
Programming Experience
1-3
I have a textbox that is bound. No problems with this, but if I enter the box, hit enter, whatever I entered disappear from the textbox. I have no code on this either, so I dont see how It can be a coding problem. i need whatever i put in that box to stay there then add to my db
 
Well I have two text boxes one is called Tow Amount and one is Driver Amount

If the Tow Amount is like 67.50, when the user hits enter i want it to fill in the Driver Amount with 65.00 and move to a combobox.

So I have this

Private Sub TAmountFocus(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTAmount.KeyDown

If e.KeyCode = Keys.Return = True Then

If txtTAmount.Text = "50" Then

dDAmount = 50.0

ElseIf txtTAmount.Text = "55" Then

dDAmount = 55.0

ElseIf txtTAmount.Text = "67.50" Then

dDAmount = 65.0

ElseIf txtTAmount.Text = "77.50" Then

dDAmount = 75.0

ElseIf txtTAmount.Text = "80" Then

dDAmount = 80.0

ElseIf txtTAmount.Text = "87.50" Then

dDAmount = 85.0

ElseIf txtTAmount.Text = "97.50" Then

dDAmount = 95.0

End If

txtDAmount.Text = Format(dDAmount, "Currency")

cboTower.Focus()

dTAmount = txtTAmount.Text

txtTAmount.Text = Format(dTAmount, "Currency")

dTotal = dTotal + dTAmount

End If

End Sub

It fills the textbox fine, but if i enter the box and change the focus it disappears and it wont add the amount to my Database. ALl other fields update to the db except this one. I am using bound controls.
 
Back at ya

dDAmount is a variable that for the Driver Amount, since they get a different amount from the Tow Amount. I store it in the variable so I can format it into currency later.
 
Wouldn't it be easier to remove all of those if statments and just do this

VB.NET:
[size=2]dDAmount = [/size][size=2]txtTAmount[/size][size=2].Text

[/size]
 
Enter As Tab Key

I have been using this code to have the enter key behave like a tab key on data entry forms. You could modify it to perform your functions. Have your tab stops set in the order you want to enter and it should work. Set the form's KeyPreview = True and paste the SUB anywhere on the form.

On form: KeyPreview = True


Private Sub Form1_KeyPress _
(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles MyBase.KeyPress

If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
If TypeOf Me.ActiveControl Is TextBox Then
Dim tb As TextBox = DirectCast(Me.ActiveControl, TextBox)
If tb.Multiline AndAlso tb.AcceptsReturn Then
e.Handled = False
Exit Sub
End If
End If
e.Handled = True
Dim oform As Form = Me.FindForm
oform.SelectNextControl(oform.ActiveControl, True, True, True, True)
oform.ActiveControl.Focus()
End If
End Sub


See if that helps.
 
levyuk I cant because some of the values are 77.50 and the drivers get paid 75. Thanks anyways.

DavidT_macktool thanks for the tip I will have to give that a try
 
Back
Top