Tab Control

  • Thread starter Thread starter Steven Smith
  • Start date Start date
S

Steven Smith

Hi guys

On my main menu I've got 4 sub menu items which all point
to the same form containg a tab control what I would like
to do is set a specific tab to be shown dependant on the
menu item which is clicked, is this achievable and how?
 
* "Steven Smith said:
On my main menu I've got 4 sub menu items which all point
to the same form containg a tab control what I would like
to do is set a specific tab to be shown dependant on the
menu item which is clicked, is this achievable and how?

Add a property to the form:

\\\
Private m_InitialTab As Integer

Public Property InitialTab() As Integer
Get
Return m_InitialTab
End Get
Set(ByVal Value As Integer)
m_InitialTab = Value
End Set
End Property
///

In, for example, the form's 'Load' event handler, you set the tab
controls 'SelectedIndex' property to 'm_InitialTab'.

Usage in the 1st menu item:

\\\
Dim f As New FooForm()
f.InitialTab = 1
f.ShowDialog()
///

In menu item 2:

\\\
Dim f As New FooForm()
f.InitialTab = 2
f.ShowDialog()
///

.... and so on.
 
Ho

tabControl1.SelectedTab = tabpage1

Hint:
Every Page of a Tab is a own Class.
Look at the Code generated by the Designer and you wil the it.
 
Hi Armin,

You are a new poster in this newsgroup and I saw more posts of you.

And I ask something that sounds maybe strange, but can you give your name
something extra (even one letter by instance Armin B. or something.

I am used to write Armin and now I it will be needed to write Armin Z. but
maybe we can do that than for you also so we know who we mean when we quote
each other.

Only a request,

Cor
 
Intellisense returns an error of 'TabPage1 not declared'
although this is the name in the tab page collection,
what am I doing wrong ?


Handles MenuItem39.Click

Dim objMaintainElevatorStatusForm As New
frmMaintenanceElevatorStatus
objMaintainElevatorStatusForm.MdiParent = Me
objMaintainElevatorStatusForm.Show()

objMaintainElevatorStatusForm.TabControl1.SelectedTab =
TabPage1

End Sub
 
That is superb, very impressive !

never realised you could do that, thanks again

regards Steve
 
The Name "TabPage1" was only a Sample....

I don't know how you named your TabPages.

Click at you TabControl in the Designer.

Then select the TabPage you want and click into the TabPage.

In the Property Windows you now see the Name of your TabPage.
 
Intellisense returns an error of 'TabPage1 not declared'
although THIS IS the name in the tab page collection,
what am I doing wrong ?
 
I tried that cor it doesn't seen to like that either
returning 'Value of type integer cannot be convereted to
System.Windows.Form.TabPage' this must be something to do
with the interaction between the 2 forms (parent and
child) as when using me.tabcontrol.selectedindex it
returns no errror
 
* "Steven Smith said:
That is superb, very impressive !

never realised you could do that, thanks again

As an alternative, you can overload the form's constructor to pass the
initial tab index:

\\\
Public Sub New(ByVal InitialTab As Integer)
MyBase.New()
Me.TabControl1.SelectedIndex = InitialTab
End Sub
///

Usage:

\\\
Dim f As New FooForm(<tab number>)
///
 
Hi Steven,
I call my tabcontrol always a tabpage, will be the last time. :-)

so it is
me.tabcontrol1.selectedindex = x

I hope this goes better, but you can also call it by name like Ford Perfect
says.

Cor
 
Arrgh

Just tested your first solution and it doesn't seem to
work for me, returns no errors but regardless of which
menu item is clicked in the parent form the child always
loads with the first tag showing...???
 
Cor these examples work fine if they are being called
from within the form that contains the tabcontrol but
I've got one form (with tab control) which is called from
the parents main menu four times and dependent on which
of the parents menu items is clicked should in turn
specify which of the four tabs are first shown when the
form loads so as far as I can gather (maybe I'm wrong)
the statment which governs the correct tab to display
must be executed before the child form (with the tab
control)loads...

so when I click an item in the parents main menu I
trigger:

\\\
Handles MenuItem42.Click

Call Merge_menu()

Dim objMaintainElevatorStatusForm As New
frmMaintenanceElevatorStatus

objMaintainElevatorStatusForm.MdiParent = Me

objMaintainElevatorStatusForm.Show()

End Sub
///

so just before the .show() statement I need to have
something along the lines of

\\\
objMaintainElevatorStatusForm.tabcontrol1.selectedindex =
x
///


however it does not like = x or any other other integer
or variable name
 
Sorry Herfried

I decided to ignore this bit...

In, for example, the form's 'Load' event handler, you set
the tab
controls 'SelectedIndex' property to 'm_InitialTab'

your original solution works perfectly well... :)

regards steve
 
Maybe the Code is not in the same windows.Form as the TabPage.......

Try this:

objMaintainElevatorStatusForm.tabcontrol1.selectedTab =
objMaintainElevatorStatusForm.tabpage1
 
Hi Steven,

I never work with MDI, so you will see I never answer question about that
here, that is for Armin Zingler.

But when I would do it what you want, I think would create a public sub in
my form with the tabpage and just do in my parent form something like this

\\\
'In my childform
public sub tabpage (byval tabname as string)
'Use the tabname I did forget that the index can give errors
tabcontrol.selectedtab=tabname
end sub
///
\\\
'In my parentform
Handles menuItem43
mymidipage("MyTabpage1")
///

But maybe Armin Zingler sees this and he knows this much better than me.

Cor
 
I see you found the solution, but this looks stupid so a little correction.
\\\
'In my childform
public sub tabpage (byval tabname as string)
'Use the tabname I did forget that the index can give errors
tabcontrol.selectedtab=tabname
end sub
///
\\\
'In my parentform
Handles menuItem43
mymidipage.tabpage("MyTabpage1")
///
cor
 
* "Steven Smith said:
Just tested your first solution and it doesn't seem to
work for me, returns no errors but regardless of which
menu item is clicked in the parent form the child always
loads with the first tag showing...???

Works perfectly for me. Are you sure you included the code for setting
the selected tab in the dialog and set the form's custom 'InitialTab'
property before showing it?
 
Back
Top