Results 1 to 7 of 7

Thread: [2.0] TabControl in C#

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    18

    Exclamation [2.0] TabControl in C#

    I am creating a windows application in C# using Visual Studio 2005.

    I get an error when I try to Hide Salary tab by discarding what I created earlier...

    Error: Cannot implicitly convert type 'void' to 'System.Windows.Forms.TabPage'
    Line: tabpg = this.tabctrlEmployeeInfo.TabPages.Add("tabpgSalary");

    Thank you,
    This is the entire code Function
    ---------------------------------------------------------------------------------------------------------------------

    //Called to dynamically show/hide the "Salary" tab page
    //
    private void showSalaryToolStripMenuItem_Click(object sender, EventArgs e)
    {
    if (this.showSalaryToolStripMenuItem.Text.StartsWith("Show"))
    {
    //Show Salary tab, which we create on the fly
    //
    TabPage tabpg;
    tabpg = new TabPage("Salary");
    tabpg.Name = "tabpgSalary";
    tabpg.ForeColor = Color.Red;

    Label lbl;
    lbl = new Label();
    lbl.Text = "Salary:";
    lbl.Location = new Point(30, 40);

    TextBox txt;
    txt = new TextBox();
    txt.Name = "txtSalary";
    txt.Location = new Point(100, 37);
    txt.ReadOnly = true;
    txt.Size = new Size(200, 26);

    tabpg.Controls.Add(txt);
    tabpg.Controls.Add(lbl);
    this.tabctrlEmployeeInfo.TabPages.Add(tabpg);

    if (this.employee != null)
    {
    //we have an employee being displayed, show their salary
    txt.DataBindings.Add("Text", this.employee, "FormattedSalary");
    }
    this.showSalaryToolStripMenuItem.Text = "Hide Salary"; //flip menu text
    }
    else
    {
    //
    //Hide Salary tab by discarding what we created earlier...
    //
    TabPage tabpg;
    tabpg = this.tabctrlEmployeeInfo.TabPages.Add("tabpgSalary");
    this.tabctrlEmployeeInfo.TabPages.Remove(tabpg);

    this.showSalaryToolStripMenuItem.Text = "Show Salary"; //flip menu text
    }


    }

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2.0] TabControl in C#

    Why are you adding a tabpage to tabpg then trying to remove it? If you want it hidden, just change it's Visible property to false.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    18

    Re: [2.0] TabControl in C#

    Quote Originally Posted by kasracer
    Why are you adding a tabpage to tabpg then trying to remove it? If you want it hidden, just change it's Visible property to false.
    Thank you,

    Please could you give me the syntax to change the tabcontrol's visible property to false.

    Regards

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2.0] TabControl in C#

    MyTabControl.Visible = false;

    or if you want to make your tabpage invisible

    MyTabPage.Visible = false;
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    18

    Re: [2.0] TabControl in C#

    Quote Originally Posted by kasracer
    MyTabControl.Visible = false;

    or if you want to make your tabpage invisible

    MyTabPage.Visible = false;
    Thank you,

    But I see no visible property for my TabPage.

    As you already know, I am creating this TabPage Dynamically.

    And I want to Hide and Show this Tab.

    Thank you

  6. #6
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2.0] TabControl in C#

    Oh sorry, I forgot it does not have a Visible property. Use the Hide() and Show() methods.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] TabControl in C#

    Hide and Show don't work with tab pages. If you want a tab page to not be visible then you have to remove it from the tab control. Your immediate problem is this line:
    Code:
    tabpg = this.tabctrlEmployeeInfo.TabPages.Add("tabpgSalary");
    That is trying to assign the result of the Add method to a TabPage variable, but that method doesn't return a TabPage object, or anything else for that matter. I think what you mean is:
    Code:
    tabpg = this.tabctrlEmployeeInfo.TabPages("tabpgSalary");
    without the Add. That will get the TabPage with that name.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width