Link to home
Start Free TrialLog in
Avatar of Kevin
KevinFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kevin

ASKER

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
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)
Avatar of Kevin

ASKER

Thanks Eric.

Works great!!!