C
chadwick
Hi everyone -
I have a form that contains a TabControl object with 2 tab pages,
TabPage1 and TabPage2. TabPage1 contains two text boxes and a cancel
button, which closes the form.
I would like to validate the data contained in two text boxes on
TabPage1 before the user moves to TabPage2, using TabPage1's
validating event. My code looks like this:
Public Class TabPageValidationTester
Private Sub ValidateTextBoxes()
'Otherwise complex processing simplified here.
If TextBox1.Text = TextBox2.Text Then
Dim ex As New System.Exception("Strings in _
TextBox1 and TextBox2 must be different.")
Throw ex
End If
End Sub
Private Sub TabPage1_Validating(ByVal sender As System.Object, _
ByVal e As
System.ComponentModel.CancelEventArgs) _
Handles TabPage1.Validating
Try
ValidateTextBoxes()
Catch ex As Exception
MessageBox.Show("Error. " & ex.Message)
e.Cancel = True
End Try
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class
I have a form that contains a TabControl object with 2 tab pages,
TabPage1 and TabPage2. TabPage1 contains two text boxes and a cancel
button, which closes the form.
I would like to validate the data contained in two text boxes on
TabPage1 before the user moves to TabPage2, using TabPage1's
validating event. My code looks like this:
Public Class TabPageValidationTester
Private Sub ValidateTextBoxes()
'Otherwise complex processing simplified here.
If TextBox1.Text = TextBox2.Text Then
Dim ex As New System.Exception("Strings in _
TextBox1 and TextBox2 must be different.")
Throw ex
End If
End Sub
Private Sub TabPage1_Validating(ByVal sender As System.Object, _
ByVal e As
System.ComponentModel.CancelEventArgs) _
Handles TabPage1.Validating
Try
ValidateTextBoxes()
Catch ex As Exception
MessageBox.Show("Error. " & ex.Message)
e.Cancel = True
End Try
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class