Results 1 to 7 of 7

Thread: [Resolved] [2.0] Multi tab at run time

  1. #1

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Resolved [Resolved] [2.0] Multi tab at run time

    Hi all I' working on an app that will show contact info of clients, the problem arrises is that some clients have have more than one contact.

    I decided the best way to sho the data would be via a tabcontrol which statrs of with one tabpage with 2 text boxes and 2 lables. holding contact name and address. now if there is more than one contact i would then do the following

    Code:
    TabPage tab  ;
    foreach(Control C in tabPage1.Controls){
    				MessageBox.Show(C.Name.ToString());
    			}
    			
    			
    tab =  this.tabPage1;
    			
    foreach(Control C in tab.Controls){
    			MessageBox.Show(C.Name.ToString());
    			}
    			
    tabControl1.TabPages.Add(tab);
    this does add the new tab and the for each says it contains the controls and I get no errors but the controls are not visable. I beleive it's due to the fact the names of the controls on the newly add tab conflict with the previous control names.

    Can anyone please help me achive my goal of add idetincle tabspages to a tab control at run time.

    Many thanks

  2. #2
    Lively Member
    Join Date
    Jun 2006
    Location
    City of Angles. Right Angles.
    Posts
    110

    Re: [2.0] Multi tab at run time

    You are trying to make a copy of a tab that already exists? I don't know if you can do that, but if you can, you would have to do it like tab = new this.tabPage1() I would think.

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

    Re: [2.0] Multi tab at run time

    What you should do is create your own class that inherits TabPage and adds the controls you desire. Then you simply add instances of your class to a TabControl instead of vanilla TabPages.
    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

  4. #4
    Lively Member
    Join Date
    Jun 2006
    Location
    City of Angles. Right Angles.
    Posts
    110

    Re: [2.0] Multi tab at run time

    jmcilhinney, can you suggest a good search query or possibly one of your many links in your sig that will show me how to inherit stuff? I was trying to figure it out on my own, but I couldn't find a search query that found useful results. It seems like something useful to learn. I only know that when you declare your class you put : TabPage after the declaration. I couldn't figure out how to access its properties or initialize it.
    Code:
    public class MyTab() : TabPage

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

    Re: [2.0] Multi tab at run time

    You already know exactly how to do it because you do it every time you design a form. Every form you create inherits the Form class. Here's the default contents of the user code file for a form in C# 2005:
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
        }
    }
    How do you access the inherited members in a form? You would exactly the same thing in any other class to access its inherited members. How do you add new functionality to a form? You would do exactly the thing in any other class to add new functionality to it.
    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

  6. #6
    Lively Member
    Join Date
    Jun 2006
    Location
    City of Angles. Right Angles.
    Posts
    110

    Re: [2.0] Multi tab at run time

    D'oh... I guess I could have figured that one out on my own. Thanks though.

  7. #7

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Re: [2.0] Multi tab at run time

    Thanks very much guys been a great help just tried this out got a partialy working version more just need a bit more work doing to it.

    Thanks again.


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