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 TabPageValidati onTester
Private Sub ValidateTextBox es()
'Otherwise complex processing simplified here.
If TextBox1.Text = TextBox2.Text Then
Dim ex As New System.Exceptio n("Strings in _
TextBox1 and TextBox2 must be different.")
Throw ex
End If
End Sub
Private Sub TabPage1_Valida ting(ByVal sender As System.Object, _
ByVal e As
System.Componen tModel.CancelEv entArgs) _
Handles TabPage1.Valida ting
Try
ValidateTextBox es()
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.EventArg s) 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 TabPageValidati onTester
Private Sub ValidateTextBox es()
'Otherwise complex processing simplified here.
If TextBox1.Text = TextBox2.Text Then
Dim ex As New System.Exceptio n("Strings in _
TextBox1 and TextBox2 must be different.")
Throw ex
End If
End Sub
Private Sub TabPage1_Valida ting(ByVal sender As System.Object, _
ByVal e As
System.Componen tModel.CancelEv entArgs) _
Handles TabPage1.Valida ting
Try
ValidateTextBox es()
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.EventArg s) Handles btnCancel.Click
Me.Close()
End Sub
End Class
Comment