Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

How to make a tabpages visible

Hi I have an issue. I have removed certain tabpages for a tabcontrol as follows
   'Display Default Tab
            TabPayment.Controls.Remove(TabCheck)
            TabPayment.Controls.Remove(TabBankDraft)
            TabPayment.Controls.Remove(TabFundsTransfer)
            TabPayment.Controls.Remove(TabCreditCard)
            TabPayment.Controls.Remove(TabAdjustment)
            TabPayment.Controls.Remove(TabCash)


however if i want to redisplay certain tabs using the syntax below it does not work. Any Ideas?
    TabPayment.Controls.Add(TabCheck)

0
anwarmir
Asked:
anwarmir
  • 4
  • 2
1 Solution
 
S-TwilleyCommented:
Ok, can't really give a better answer than this without seeing more of your code, like where TabCheck is defined... but this simple code adds a new tab which is visible... so you can modify it for your own purposes and see if that works:

        Dim x As New TabPage()
        x.Text = "Hello"
        TabControl1.Controls.Add(x)
        x.Visible = True


If this isn't working, post some more of your code up including the declaration of TabCheck
0
 
wyoung76Commented:
Couldn't you just go through and .Hide each of the TabPages you don't need, and .Show the ones you intend to show again later?
0
 
anwarmirAuthor Commented:
If u mean the visible property then No as this does not seem to work.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
S-TwilleyCommented:
I did just try using the Hide and Show property... didn't seem to work for some reason as anwarmir said...

I did try this and it seems to show as visible though

    Dim x As New TabPage("Hello")
    Dim y As New TabPage("Hello2")

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TabControl1.Controls.Add(x)
        TabControl1.Controls.Add(y)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TabControl1.TabPages.Remove(x)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TabControl1.TabPages.Add(x)
    End Sub
0
 
S-TwilleyCommented:
actually...

replace the initial adding to this

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TabControl1.TabPages.Add(x)
        TabControl1.TabPages.Add(y)
    End Sub

This will allow duplicate pages of x to be added, so you may want to check that there isn't already an "X" page in the control
0
 
anwarmirAuthor Commented:
For some reason I cant get it to work...I lost all my tabs in design view and to get the latet one again from sourcesafe. Can u please help...On the form load event I remove the tabs to show only the default ones. But depending on the functionality being invoked i am adding the code like this. How would I adapt the code with regards to what u said previouly. Also how can i maintain the position of the tab so that tabAdjustment is always the last one.


        ''Configure from for Maintain Payments
        'If Me.FormName = CashAppFormType.MaintainPayment Then
        '    Select Case Me.Paymentmethod
        '        Case "ca_Pymt_Cash"
        '            TabPayment.Controls.Add(TabCash)
        '            TabPayment.Controls.Add(TabAdjustment)
        '        Case "ca_Pymt_CC"
        '            TabPayment.Controls.Add(TabCreditCard)
        '            TabPayment.Controls.Add(TabAdjustment)
        '        Case "ca_Pymt_Check"
        '            TabPayment.Controls.Add(TabCheck
        '            TabPayment.Controls.Add(TabAdjustment)

        '        Case "ca_Pymt_Draft"
        '            TabPayment.Controls.Add(TabBankDraft)
        '            TabPayment.Controls.Add(TabAdjustment)

        '        Case "ca_Pymt_EFT"
        '            TabPayment.Controls.Add(TabFundsTransfer)
        '            TabPayment.Controls.Add(TabAdjustment)
        '    End Select
        'End If
0
 
S-TwilleyCommented:
Just to prevent duplicate Tab Pages being added, I've written a short method

    Sub AddTabPage(ByRef NewPage As TabPage, ByRef ParentTabControl As TabControl)
        If Not ParentTabControl.TabPages.Contains(NewPage) Then
            ' Tab page is currently not part of the Parent Tab Control
            ParentTabControl.TabPages.Add(NewPage)
        Else
            ' Add any code here if you like
        End If
    End Sub

============================

Then with your Select Case

        If Me.FormName = CashAppFormType.MaintainPayment Then
            Select Case Me.Paymentmethod
                Case "ca_Pymt_Cash"
                    AddTabPage TabCash, TabPayment
                    AddTabPage TabAdjustment, TabPayment

                Case "ca_Pymt_CC"
                    AddTabPage TabCreditCard, TabPayment
                    AddTabPage TabAdjustment, TabPayment

                Case "ca_Pymt_Check"
                    AddTabPage TabCheck, TabPayment
                    AddTabPage TabAdjustment, TabPayment

                Case "ca_Pymt_Draft"
                    AddTabPage TabBankDraft, TabPayment
                    AddTabPage TabAdjustment, TabPayment

                Case "ca_Pymt_EFT"
                    AddTabPage TabFundsTransfer, TabPayment
                    AddTabPage TabAdjustment, TabPayment
            End Select
        End If

===========

As for making sure tabAdjustment is the last one, Im not sure how to adjust the order of tabpages once they have been added, but a new tab page is always added to the end of the list as far as i know, so as long as you add TabAdjustment last, it should be fine
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now