Tab pages- enabling and disabling (or mimicing as seen in C# thread)

I had a search for this and found something about mimicing the enabling and disabling of tabpages but unfortunately couldn't convert it from C# (im a beginner and only with vb).

I have a shared variable called op as a string. It has three states, "Add", "Edit" and "Delete".
When i open the form (with three different buttons) it changes the variable as required.
I have three tabpages add, edit and delete and i want the other two to be unselectable.( I didn't want three different forms).

Is there any way i can do this I tried playing with the tabcontrol_selecting method, but have had no success.
Cheers.
-- Ash Clarke



Answer this question

Tab pages- enabling and disabling (or mimicing as seen in C# thread)

  • Critcho

    Thanks so much Shakalama, this is just what i needed.
    I did notice one problem as i was coding it:

    The line: Savedpage1 = Me.TabControl1.TabPages(1)

    Should read: Savedpage1 = Me.TabControl1.TabPages(0)

    For anyone who didn't know, Tabpages in the collection dialogue always start with 0 then 1 then 2, for tabpage1, tabpage2 and tabpage3 etc.

    Anyway, thanks again, like i said, exactly what i needed.

    Cheers
    -- Ash Clarke


  • Srreh

    Yeah i know, i wanted to write that, but just couldnt think how to say it.

    Cheers
    -- Ash Clarke


  • Joe McGrath

    hi,

    you want to hide first tabpage i wanted to hide the second anyway which tab page is not the problem the problem was the way how to do it if you want to control many pages you just save them one by one or even you can make array of them and to hide and show which page you want

    hope this helps



  • dronick

    ok,jmc

    for me i have a form that will capture loads of data entery per record i divided them in 8 groups of data in 8 tabpages, and those records depending on other data entery like for example if textbox1.text < 10$ then textbox2.enable = false , but in a big scale you may be disable 5 textbox's (ie entire tabpage)

    now i remove the tabpage and show it again but if i were able to disable it , it will looks better

    best regards



  • dredrunde

    Basically, as others have said, this is bad UI. If something exists on a tab page, users expect to be able to select it, even if the contents may be disabled. Adding/removing tab pages is a better solution if you must use tab pages. If only one is available at a time, then they should be three forms, or one form with three composite controls, which get shown/hidden so the right one is visible every time.



  • spillai

    If you don't want the TabPages to be selectable then why even show them That seems to completely defeat the purpose of the TabControl. It seems to me that you should have three different forms. If they share functionality then they should all derive from the same base class that contains that commonality. At the very least, don't use a TabControl. Either use threee Panels and Hid ethe two you aren't using or else create a UserControl for each operation and only add an instance of the one you need. Finally, it's hard to say for sure with so little information but I'm guessing that you're misusing a Shared variable as well. You shouldn't make a variable Shared just so that you don't need an instance to access if in fact the variable really should be a member of an instance, as it sounds to me like it should in this case.
  • Seb_london

    @ Shakalama - C# Thread
    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=13077&SiteID=1

    @jmcilhinney and cgraus
    I have my reasons, the main being that i would have to create 7 more forms instead of two.
    I think i might rethink my choice of a tabcontrol (it does look pretty) and just use panels instead.

    Cheers for your comments
    -- Ash Clarke


  • Big H

    hi,

    actualy i'm searching for that in C# if you don't mind give me the link to it and i'll convert it to you in VB

    thx



  • Mike12345

    AshClarke wrote:
    For anyone who didn't know, Tabpages in the collection dialogue always start with 0 then 1 then 2, for tabpage1, tabpage2 and tabpage3 etc.
    Every array or collection in .NET is zero-based. It stems from the fact that the indexes were originally offsets from a memory address. They can still be considered offsets from the beginning of an array or collection. The first item is offset zero positions from the start, the second item is offset one position from the start, etc.

  • jinjun

    hi,

    first of all if you check this link again you will find that trick didn't work, neither in c# or VB so you have to search for other solution, anyway for myself i used hide/show the tabcontrol

    this is a tabcontrol with 2 tabpages , tabpage one contain checkbox used to hide tabpage2 take care from the page names it will confuse you like it did to me, so name the tabpages again with meaningfull name



    Public Class Form1
    Dim Savedpage1 As TabPage
     
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'save the pages to be able to remove them and themm again without losing controls
    Savedpage1 =
    Me.TabControl1.TabPages(1)
     

    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked = True Then

    showpage(Me.TabPage2, Savedpage1)
    Else

    HidePage(Me.TabPage2)
    End If

    End Sub

    Private Sub ShowPage(ByVal Tb As TabPage, ByVal saved As TabPage)
    If Not TabControl1.TabPages.Contains(Tb) Then

    TabControl1.TabPages.Add(saved)
    End If

    End Sub

    Private Sub HidePage(ByVal Tb As TabPage)
    If TabControl1.TabPages.Contains(Tb) Then

    Dim index As Integer = TabControl1.TabPages.IndexOf(Tb)
    TabControl1.TabPages.RemoveAt(index)
    End If

    End Sub
    End
    Class


     

    hope this will help



  • Tab pages- enabling and disabling (or mimicing as seen in C# thread)