PDA

Click to See Complete Forum and Search --> : [Resolved] [2.0] Multi tab at run time


Bombdrop
Jun 22nd, 2006, 06:41 AM
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


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

supertotallyawesome
Jun 22nd, 2006, 09:29 PM
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.

jmcilhinney
Jun 22nd, 2006, 10:52 PM
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.

supertotallyawesome
Jun 22nd, 2006, 10:58 PM
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.

public class MyTab() : TabPage

jmcilhinney
Jun 22nd, 2006, 11:45 PM
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: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.

supertotallyawesome
Jun 22nd, 2006, 11:51 PM
D'oh... I guess I could have figured that one out on my own. Thanks though. :)

Bombdrop
Jun 23rd, 2006, 03:15 AM
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.

:wave: :thumb: :wave: