TabConrol in VB.Net - How to fully disable a tab page?

Morning,

I am using a Tab control in my windows form which contains two tabs.

I want to accomplish, where one tab is enabled the other is completely disabled (greyed out), so the user cannot even access/view the information in the other tab.

I have attempted the below in line 11

frmMain.TabControl1.TabPages(0).Enabled = False

But by doing this the user can still click on the tabpage and see the information inside. While the page has been disabled from any further changes. I would like the actual tabpage header disabled as well, so that when the user attempts to click on the tabpage that is disabled, nothing will happen and the user will not be able to even see the contents of the tabpage that has been disabled.

Kindly provide assistance on how to accomplish this in VB.Net.

Regards,
N


Private Sub btnCNVOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCNVOK.Click

        Dim xFile As New XmlDocument()
        xFile.Load("C:\XMLFile.xml")

        Dim root = xFile.DocumentElement

        If txtCNVChqVerf.Text = root.GetElementsByTagName("NextChqNum")(0).InnerText Then

            Me.Close()
            frmMain.TabControl1.TabPages(0).Enabled = False
            frmMain.TabControl1.TabPages(1).Show()

        Else

            MsgBox("Cheque number incorrect." & vbNewLine & "Please try again.", MsgBoxStyle.Exclamation, "Cheque Validation")

        End If

    End Sub

Open in new window

LVL 1
KevinInformation TechnologyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Éric MoreauSenior .Net ConsultantCommented:
This is not built-in the control. Your best option is to create an extender control with this feature.

I have the full code available at http://emoreau.com/Entries/Articles/2004/05/The-incomplete-TabControl.aspx

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
KevinInformation TechnologyAuthor Commented:
Thank you very much Eric.

This works great on my main form.

I have two more questions though.

1. I am getting a warning from the TabControlEx class saying 'Variable 'im' is used before it has been assigned a value. A null reference exception could result at runtime.' Can I safely ignore this warning?

2. The code I posted above in my first posting is from another one of my forms. Essentially once the user inputs a value that matches with a value in my XML file on a different form, one of the tabs on the main form will disable and the other will enable.

How would I achieve this using your class?

Ive read in a few forums that I would need to include a reference to the actual instance. While I kind of have an idea of what this means, I am not able to figure it out.

The example I am looking at is here: http://stackoverflow.com/questions/15748857/call-a-tabpage-from-a-separate-window-form

I thought when I code in:

frmMain.TabControl1.DisablePage(TabPage1)

That I would be referencing the instance of the control that way. But that doesnt seem to be correct because im getting a 'TabPage1" is not declared.

Im not quite sure on how to proceed.

Kindly advise.

Regards,
N
Éric MoreauSenior .Net ConsultantCommented:
1, Yes or you can initialize it to Nothing if you want to remove the warning.
2. You need to set the Modifiers property (of the TabControl and the TabPage) to Public. You also need to prefix TabPage1 with the form's instance name (frmMain.TabPage1)
KevinInformation TechnologyAuthor Commented:
Thanks Eric.

Works great!!!
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.NET

From novice to tech pro — start learning today.