|
-
Jul 15th, 2003, 11:35 PM
#1
Thread Starter
Lively Member
Question about the Error Provider
Can you use one error provider to validate multiple controls on a form. I am using one on a form that will validate the controls the first time there is an error in the first control but if the error is fixed in the first control and not fixed in the secon control the error provider goes away. Is there something wrong with the code that I have posted below. It checks two text boxes and makes sure that they contain Alpha characters and not Numeric numbers as the first character.
Private Sub txtAccountName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtAccountName.Validating
If IsNumeric(txtAccountName.Text) Then
ErrorProvider1.SetError(txtAccountName, "Not a numeric value.")
Else
' Clear the error.
ErrorProvider1.SetError(txtAccountName, "")
End If
End Sub
Private Sub txtIssuingBank_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtIssuingBank.Validating
If IsNumeric(txtAccountName.Text) Then
ErrorProvider1.SetError(txtIssuingBank, "Not a numeric value.")
Else
' Clear the error.
ErrorProvider1.SetError(txtIssuingBank, "")
End If
-
Jul 17th, 2003, 05:08 AM
#2
The code you posted checks txtAccount name in both subroutines, ignoring txtIssuingBank. Apart from that, this code looks ok to me.
VB Code:
Private Sub txtAccountName_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles _
txtAccountName.Validating
If IsNumeric(txtAccountName.Text) Then
ErrorProvider1.SetError(txtAccountName, "Not a numeric value.")
Else
' Clear the error.
ErrorProvider1.SetError(txtAccountName, "")
End If
End Sub
Private Sub txtIssuingBank_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles _
txtIssuingBank.Validating
If IsNumeric([b]txtAccountName.Text[/b]) Then
ErrorProvider1.SetError(txtIssuingBank, "Not a numeric value.")
Else
' Clear the error.
ErrorProvider1.SetError(txtIssuingBank, "")
End If
This world is not my home. I'm just passing through.
-
Jul 17th, 2003, 11:01 AM
#3
Thread Starter
Lively Member
Thanks trisuglow for catching that error. I thought I fixed it before.
Thanks
-
Jul 17th, 2003, 01:59 PM
#4
Addicted Member
Argh, It's much eaiser to keep track of if you validate all your controls in the same spot
Code:
Private Sub TextBox_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles txtAccountName.Validating, txtIssuingBank.Validating
Dim Control As Windows.Forms.Control = sender
If IsNumeric(Control.Text) Then
ErrorProvider1.SetError(Control, "Not a numeric value.")
Else
' Clear the error.
ErrorProvider1.SetError(Control, "")
End If
End Sub
Last edited by MasterBlaster; Jul 17th, 2003 at 02:16 PM.
"And most of the evils of society can, in fact, be cured through information. We have a society that has been disinformed and based on the disinformation has made irrational choices. And that's what I mean by 'ignorance.' People, who ordinarily might be smart, are deprived of the data by which to make a rational decision, don't have the data to do it."
Frank Zappa
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|