Ok I understand your problem now. But I am stumped as to why this is
happening. I created a dummy project and did not encounter this problem.
I tried different combinations of CausesValidation on the tab and its
container controls and observed that as long as the txtBox has its
CausesValidation = True, the Validating event is always raised AS SOON as the
txtBox loses focus.
I am pasting my code, if its going to be of any help. If you can post your
code and we can see what you are missing.
\\\
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents tbsOptions As System.Windows.Forms.TabControl
Friend WithEvents tbsOptions1 As System.Windows.Forms.TabPage
Friend WithEvents tbsOptions2 As System.Windows.Forms.TabPage
Friend WithEvents txttbs1 As System.Windows.Forms.TextBox
Friend WithEvents txttbs2 As System.Windows.Forms.TextBox
Friend WithEvents btntbs2 As System.Windows.Forms.Button
Friend WithEvents btntbs1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.tbsOptions = New System.Windows.Forms.TabControl
Me.tbsOptions1 = New System.Windows.Forms.TabPage
Me.btntbs1 = New System.Windows.Forms.Button
Me.txttbs1 = New System.Windows.Forms.TextBox
Me.tbsOptions2 = New System.Windows.Forms.TabPage
Me.btntbs2 = New System.Windows.Forms.Button
Me.txttbs2 = New System.Windows.Forms.TextBox
Me.tbsOptions.SuspendLayout()
Me.tbsOptions1.SuspendLayout()
Me.tbsOptions2.SuspendLayout()
Me.SuspendLayout()
'
'tbsOptions
'
Me.tbsOptions.CausesValidation = False
Me.tbsOptions.Controls.Add(Me.tbsOptions1)
Me.tbsOptions.Controls.Add(Me.tbsOptions2)
Me.tbsOptions.ItemSize = New System.Drawing.Size(0, 21)
Me.tbsOptions.Location = New System.Drawing.Point(8, 16)
Me.tbsOptions.Name = "tbsOptions"
Me.tbsOptions.SelectedIndex = 0
Me.tbsOptions.Size = New System.Drawing.Size(464, 272)
Me.tbsOptions.TabIndex = 0
'
'tbsOptions1
'
Me.tbsOptions1.CausesValidation = False
Me.tbsOptions1.Controls.Add(Me.btntbs1)
Me.tbsOptions1.Controls.Add(Me.txttbs1)
Me.tbsOptions1.Location = New System.Drawing.Point(4, 25)
Me.tbsOptions1.Name = "tbsOptions1"
Me.tbsOptions1.Size = New System.Drawing.Size(456, 243)
Me.tbsOptions1.TabIndex = 0
Me.tbsOptions1.Text = "tbs1"
'
'btntbs1
'
Me.btntbs1.Location = New System.Drawing.Point(16, 144)
Me.btntbs1.Name = "btntbs1"
Me.btntbs1.Size = New System.Drawing.Size(120, 56)
Me.btntbs1.TabIndex = 1
Me.btntbs1.Text = "GoTo TBS2"
'
'txttbs1
'
Me.txttbs1.Location = New System.Drawing.Point(16, 32)
Me.txttbs1.Name = "txttbs1"
Me.txttbs1.Size = New System.Drawing.Size(128, 22)
Me.txttbs1.TabIndex = 0
Me.txttbs1.Text = ""
'
'tbsOptions2
'
Me.tbsOptions2.CausesValidation = False
Me.tbsOptions2.Controls.Add(Me.btntbs2)
Me.tbsOptions2.Controls.Add(Me.txttbs2)
Me.tbsOptions2.Location = New System.Drawing.Point(4, 25)
Me.tbsOptions2.Name = "tbsOptions2"
Me.tbsOptions2.Size = New System.Drawing.Size(456, 243)
Me.tbsOptions2.TabIndex = 1
Me.tbsOptions2.Text = "tbs2"
'
'btntbs2
'
Me.btntbs2.Location = New System.Drawing.Point(32, 112)
Me.btntbs2.Name = "btntbs2"
Me.btntbs2.Size = New System.Drawing.Size(112, 48)
Me.btntbs2.TabIndex = 1
Me.btntbs2.Text = "GoTo TBS1"
'
'txttbs2
'
Me.txttbs2.Location = New System.Drawing.Point(32, 24)
Me.txttbs2.Name = "txttbs2"
Me.txttbs2.Size = New System.Drawing.Size(128, 22)
Me.txttbs2.TabIndex = 0
Me.txttbs2.Text = ""
'
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.BackColor = System.Drawing.SystemColors.GrayText
Me.ClientSize = New System.Drawing.Size(499, 329)
Me.Controls.Add(Me.tbsOptions)
Me.Name = "Form1"
Me.Text = "Test Project"
Me.tbsOptions.ResumeLayout(False)
Me.tbsOptions1.ResumeLayout(False)
Me.tbsOptions2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.tbsOptions1.Visible = True
Me.tbsOptions2.Visible = False
End Sub
Private Sub btntbs1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btntbs1.Click
Me.tbsOptions1.Visible = False
Me.tbsOptions2.Visible = True
End Sub
Private Sub btntbs2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btntbs2.Click
Me.tbsOptions1.Visible = True
Me.tbsOptions2.Visible = False
End Sub
Private Sub txttbs1_Validating(ByVal sender As System.Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txttbs1.Validating
If IsNumeric(txttbs1.Text) Then
Else
MsgBox("Non numeric data unacceptable!")
txttbs1.SelectAll()
e.Cancel = True
End If
End Sub
End Class
///
HTH