Creating Tab control at runtime in VB.Net

I have created a tab control at run time like this

Public Class Form1
    Public sTab As TabControl

Form1_Load
            sTab = New TabControl
            sTab.Name = "Tab" & ix
            sTab.Left = 500
            sTab.Width = 1000

            sTab.TabPages.Add(New TabPage("Page 1"))
            sTab.TabPages.Add(New TabPage("Page 2"))
            sTab.TabPages.Add(New TabPage("Page 3"))

            Me.Controls.Add(sTab)
End Sub

Now I want to select the a tab page not from clicking on it but from another event such as

Sub B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
        sTab.SelectTab(2)
end sub

End Class

Why is this wrong???
keymacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Works fine for me. Are you receiving an exception?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BrobenCommented:
the only thing that I can see with your code is:

sTab.Name = "Tab" & ix

the ix will throw a build error. Other than that, it works fine. Could it be that the tab strip is positioned 500 points from the left and that you cannot see the tab strip?

Perhaps you could be more specific about what is not working?
0
keymacAuthor Commented:
There should be a

For ix = 1 to 4
next

Loop around the creation of the stab code

If you click the button the selected tab does not change
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

käµfm³d 👽Commented:
If you are using a loop around this code, then you are creating 4 TabControl objects, but placing them all in the same spot--in essence, you only see 1 TabControl. So what you are viewing as "selected tab does not change," might actually be occurring on one of the TabControls you do not see. Try altering the location for each subsequent TabControl added in your loop.
0
BrobenCommented:
exactly what I was going to say
remove the loop unless you want 4 tab strips.... I can't see why you would?
0
BrobenCommented:
to prove the point, add the following line after "sTab.Name = "Tab" & ix"

sTab.Top = 10 + (ix * 100)

this will show all 4 tab strips
then you can click your button and see what happens... only one tab strip responds
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.