tabcontrol, removing and adding tabs and trying to navigate between them

Grinski

Member
Joined
Apr 16, 2010
Messages
7
Programming Experience
Beginner
Thank you for your help in advance and I'm sorry if this is obvious but I am horribly new to vb.net.

I want to remove all the tabs in a tab control, then be able to re-add them out of order, remove them as needed and navigate between them.

I tried using
Private Enum SelectedTabType
Name
RAddress
PAddress
PhoneDetails
OtherDetails
Disabilities
Admin
End Enum

and i named the tabs

tabName
tabRAddress
tabPAddress
tabPhoneDetails
tabOtherDetails
tabDisabilities
tabAdmin

and that works fine for navigation using (tab control name ).SelectedIndex = SelectedTabType.Admin
if i keep them in order but seems to go crazy if i remove and re-add tabs, i assume the order no longer corresponds to the enum i set up there, so that adding a tab named"tabPhoneDetails", removing it, and adding "tabDisabilities" means "tabDisabilities" is now sitting at the index "tabPhoneDetails" was ???

Should i be keeping an independent dictionary or something to track the (tab name), (tab index ) or can i extract that from a tab control?

I have tried navigating by the tab name itself but can't get that working.

I would have thought (tab control name).SelectedTab = tabRAddress would work?

Can anyone point me in the right direction? I don't know how to use debug to display the index each tab has.

Would it help if i mock up what i mean and attach it or just copy and paste the code?
 
I think I found a possible solution

This looks really clumsy to me, but if there's someone else out there who needs an answer in a hurry, they can adapt this i guess.



If tabStudent.SelectedTab.Name = "tabName" Then
If Not (tabStudent.Controls.Contains(tabRAddress)) Then
tabStudent.Controls.Add(tabRAddress)
End If
tabStudent.SelectedTab = tabRAddress
ElseIf (tabStudent.SelectedTab.Name = "tabRAddress") Or (tabStudent.SelectedTab.Name = "tabPAddress") Then
If Not (tabStudent.Controls.Contains(tabPhoneDetails)) Then
tabStudent.Controls.Add(tabPhoneDetails)
End If
tabStudent.SelectedTab = tabPhoneDetails
ElseIf (tabStudent.SelectedTab.Name = "tabPhoneDetails") Then
If Not (tabStudent.Controls.Contains(tabOtherDetails)) Then
tabStudent.Controls.Add(tabOtherDetails)
LockControls(btnNext, Lock)
LockControls(btnSave, UnLock)
End If
tabStudent.SelectedTab = tabOtherDetails

End If
 
Back
Top