help, TabControl1_SelectedIndexChanged fires on form initialize

J

Jeff C

Hello all. Please please help me come up with a solution to this
problem.
Here it goes-
--- code snipit---

'TabControl1
'
Me.TabControl1.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.TabControl1.Controls.AddRange(New
System.Windows.Forms.Control()
{Me.TabPage1, Me.TabPage2, Me.TabPage3})
Me.TabControl1.Enabled = False
Me.TabControl1.Location = New System.Drawing.Point(0, 40)
Me.TabControl1.Name = "TabControl1"
Offending Line---->>>>> Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(640, 384)
Me.TabControl1.TabIndex = 3
---------------------------------
When this control gets initialized it sets the selected index to 0,
thus firing the following code-

----------------
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

Do your stuff here...

End Sub
------------

I do NOT want anything to happen when the form is initializing. How
can I catch this or stop it from happening?
I've tried to delete the offending line, but it comes back :blush:) ...
Any ideas?
To recreate,
Add tabcontrol to form, add a page or more to the tabcontrol.
Set the selected index changed event.
Run :blush:)

THANKS!
Jeff C.
 
M

Mick Doherty

\\\
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

Static FirstChange as Boolean = True
If FirstChange = True then
FirstChange=False
Return
End If
Do your stuff here...

End Sub
///
 
J

Jeff C

Tricky tricky tricky :blush:)
Thanks,
I'll have to remember that loop with the static declaration.

Thank you very!!! much
Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top