C# .NET - adding controls to tabpages in c# using ado.net

Asked By swapna moturu
17-Mar-09 04:41 AM
my program implements the funtionality of adding and removing the tabpages and adding the controls to the tabpages .I have three tabpages as default with the controls added to it.Now rest i addtabapges with the tabcontrols addded to it.

 public partial class Form1 : Form
    {
     
        private static int pageNumber=4;

        private System.Windows.Forms.CheckBox tab2CheckBox3;
        private System.Windows.Forms.CheckBox tab2CheckBox2;
        private System.Windows.Forms.CheckBox tab2CheckBox1;
        private System.Windows.Forms.RadioButton tabRadioButton;
        private System.Windows.Forms.RadioButton tab1Radio1Button1;
        private System.Windows.Forms.RadioButton tab2Radio2Button2;
        private System.Windows.Forms.RadioButton tab3Radio3Button3;
        private System.Windows.Forms.RadioButton tab4Radio4Button4;
        private System.Windows.Forms.RadioButton tab5Radio5Button5;
        private System.Windows.Forms.RadioButton tab6Radio6Button6;
        private System.Windows.Forms.RadioButton tab7Radio7Button7;
        private System.Windows.Forms.RadioButton tab8Radio8Button8;
        private System.Windows.Forms.RadioButton tab9Radio9Button9;
        private System.Windows.Forms.RadioButton tab10Radio10Button10;
        private System.Windows.Forms.RadioButton tab11Radio11Button11;
        private System.Windows.Forms.RadioButton tab12Radio12Button12;
        private System.Windows.Forms.RadioButton tab13Radio13Button13;
        private System.Windows.Forms.RadioButton tab14Radio14Button14;
        private System.Windows.Forms.RadioButton tabRadioButton15;
        private System.Windows.Forms.RadioButton tabRadioButton16;
        private System.Windows.Forms.RadioButton tabRadioButton17;
        private System.Windows.Forms.RadioButton tabRadioButton18;
        private System.Windows.Forms.RadioButton tabRadioButton19;
        private System.Windows.Forms.RadioButton tabRadioButton20;
        private System.Windows.Forms.RadioButton tabRadioButton21;
        private System.Windows.Forms.RadioButton tabRadioButton22;
        private System.Windows.Forms.RadioButton tabRadioButton23;
        private System.Windows.Forms.RadioButton tabRadioButton24;
        private System.Windows.Forms.RadioButton tabRadioButton25;
        private System.Windows.Forms.RadioButton tabRadioButton26;
        private System.Windows.Forms.RadioButton tabRadioButton27;
        private System.Windows.Forms.RadioButton tabRadioButton28;
        private System.Windows.Forms.RadioButton tabRadioButton29;
        private System.Windows.Forms.RadioButton tabRadioButton30;
        private System.Windows.Forms.RadioButton tabRadioButton31;
        private System.Windows.Forms.RadioButton tabRadioButton32;
        private System.Windows.Forms.RadioButton tabRadioButton33;
        private System.Windows.Forms.RadioButton tabRadioButton34;
        private System.Windows.Forms.RadioButton tabRadioButton35;
        private System.Windows.Forms.RadioButton tabRadioButton36;
        private System.Windows.Forms.RadioButton tabRadioButton37;
        private System.Windows.Forms.RadioButton tabRadioButton38;
        private System.Windows.Forms.RadioButton tabRadioButton40;
        private System.Windows.Forms.RadioButton tabRadioButton41;
        private System.Windows.Forms.RadioButton tabRadioButton42;
        private System.Windows.Forms.RadioButton tabRadioButton43;
        private System.Windows.Forms.RadioButton tabRadioButton44;
        private System.Windows.Forms.RadioButton tabRadioButton45;
        private System.Windows.Forms.RadioButton tabRadioButton46;
        private System.Windows.Forms.RadioButton tabRadioButton47;
        private System.Windows.Forms.RadioButton tabRadioButton48;
        private System.Windows.Forms.RadioButton tabRadioButton49;
        private System.Windows.Forms.RadioButton tabRadioButton50;
        private System.Windows.Forms.RadioButton tabRadioButton51;
        private System.Windows.Forms.RadioButton tabRadioButton52;

        private System.Windows.Forms.RadioButton tabRadioButton53;

        private System.Windows.Forms.RadioButton tabRadioButton54;
        private System.Windows.Forms.RadioButton tabRadioButton55;
        private System.Windows.Forms.RadioButton tabRadioButton56;

        private Control control = new Control();

      
    
        private System.Windows.Forms.CheckBox tab1CheckBox1;
        private System.Windows.Forms.CheckBox tabCheckBox2;
        private System.Windows.Forms.CheckBox tabCheckBox3;
        private System.Windows.Forms.CheckBox tabCheckBox4;
        private System.Windows.Forms.CheckBox tabCheckBox5;
        private System.Windows.Forms.CheckBox tabCheckBox6;
        private System.Windows.Forms.CheckBox tabCheckBox7;
        private System.Windows.Forms.CheckBox tabCheckBox8;
        private System.Windows.Forms.CheckBox tabCheckBox9;
        private System.Windows.Forms.CheckBox tabCheckBox10;
        private System.Windows.Forms.CheckBox tabCheckBox11;
        private System.Windows.Forms.CheckBox tabCheckBox12;
        private System.Windows.Forms.CheckBox tabCheckBox13;
        private System.Windows.Forms.CheckBox tabCheckBox14;
        private System.Windows.Forms.CheckBox tabCheckBox15;
        private System.Windows.Forms.CheckBox tabCheckBox16;
        private System.Windows.Forms.CheckBox tabCheckBox17;
        private System.Windows.Forms.CheckBox tabCheckBox18;
        private System.Windows.Forms.CheckBox tabCheckBox19;
        private System.Windows.Forms.CheckBox tabCheckBox20;
        private System.Windows.Forms.CheckBox tabCheckBox21;
        private System.Windows.Forms.CheckBox tabCheckBox22;
        private System.Windows.Forms.CheckBox tabCheckBox23;
        private System.Windows.Forms.CheckBox tabCheckBox24;
        private System.Windows.Forms.CheckBox tabCheckBox25;
        private System.Windows.Forms.CheckBox tabCheckBox26;
        private System.Windows.Forms.CheckBox tabCheckBox27;
        private System.Windows.Forms.CheckBox tabCheckBox28;
        private System.Windows.Forms.CheckBox tabCheckBox29;
        private System.Windows.Forms.CheckBox tabCheckBox30;
        private System.Windows.Forms.CheckBox tabCheckBox31;
        private System.Windows.Forms.CheckBox tabCheckBox32;
        private System.Windows.Forms.CheckBox tabCheckBox33;
        private System.Windows.Forms.CheckBox tabCheckBox34;

        private System.Windows.Forms.CheckBox tabCheckBox35;
        private System.Windows.Forms.CheckBox tabCheckBox36;
        private System.Windows.Forms.CheckBox tabCheckBox37;
        private System.Windows.Forms.CheckBox tabCheckBox38;
        private System.Windows.Forms.CheckBox tabCheckBox39;
        private System.Windows.Forms.CheckBox tabCheckBox40;
        private System.Windows.Forms.CheckBox tabCheckBox41;
        private System.Windows.Forms.CheckBox tabCheckBox42;
        private System.Windows.Forms.CheckBox tabCheckBox43;
       
        private System.Windows.Forms.CheckBox tabCheckBox44;
     
    
     

        private System.Windows.Forms.TabPage tabPage1;
        private System.Windows.Forms.TabPage tabPage2;
        private System.Windows.Forms.TabPage tabPage3;
        private System.Windows.Forms.TabPage tabPage4;

   
      

        private System.Windows.Forms.RadioButton tab3RadioButton2;
        private System.Windows.Forms.RadioButton tab3RadioButton1;

        private System.Windows.Forms.TabControl tabControl1;
      
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
               private System.Windows.Forms.Label tab1Label1;
    private System.Windows.Forms.Button tab1Button1;
     
    

      
        List<TabPage> _cache = new List<TabPage>();
        public Form1()
        {
            InitializeComponent();
         

            this.tabControl1.Selected += new TabControlEventHandler(tabControl1_Selected);
         
        }

        private void InitializeComponent()
        {

            this.tab2CheckBox3 = new System.Windows.Forms.CheckBox();

            this.tab2CheckBox2 = new System.Windows.Forms.CheckBox();
            this.tab2CheckBox1 = new System.Windows.Forms.CheckBox();

            this.tabControl1 = new System.Windows.Forms.TabControl();

            this.tab1CheckBox1 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox2 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox3 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox4 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox5 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox6 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox7 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox8 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox9 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox10 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox11 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox12 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox13 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox14 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox15 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox16 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox17 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox18 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox19 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox20 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox21 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox22 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox23 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox24 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox25 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox26 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox27 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox28 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox29 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox30 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox31 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox32 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox33 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox34 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox35 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox36 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox37 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox38 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox39 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox40 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox41 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox42 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox43 = new System.Windows.Forms.CheckBox();
            this.tabCheckBox44 = new System.Windows.Forms.CheckBox();

            this.tabRadioButton = new System.Windows.Forms.RadioButton();
            this.tab1Radio1Button1 = new System.Windows.Forms.RadioButton();
            this.tab2Radio2Button2 = new System.Windows.Forms.RadioButton();
            this.tab3Radio3Button3 = new System.Windows.Forms.RadioButton();
            this.tab4Radio4Button4= new System.Windows.Forms.RadioButton();
            this.tab5Radio5Button5 = new System.Windows.Forms.RadioButton();
            this.tab6Radio6Button6 = new System.Windows.Forms.RadioButton();

            this.tab7Radio7Button7 = new System.Windows.Forms.RadioButton();
            this.tab8Radio8Button8 = new System.Windows.Forms.RadioButton();
            this.tab9Radio9Button9 = new System.Windows.Forms.RadioButton();
            this.tab10Radio10Button10 = new System.Windows.Forms.RadioButton();
            this.tab11Radio11Button11 = new System.Windows.Forms.RadioButton();
            this.tab12Radio12Button12 = new System.Windows.Forms.RadioButton();
            this.tab13Radio13Button13 = new System.Windows.Forms.RadioButton();
            this.tab14Radio14Button14 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton15 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton16 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton17 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton18 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton19 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton20 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton21 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton22 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton23 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton24 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton25 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton26 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton27 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton28 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton29 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton30 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton31 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton32 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton33 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton34 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton35 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton36 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton37 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton38 = new System.Windows.Forms.RadioButton();
          
            this.tabRadioButton40 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton41 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton42 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton43 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton44 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton45 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton46 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton47 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton48 = new System.Windows.Forms.RadioButton();

            this.tabRadioButton49 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton50 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton51 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton52 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton53 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton54 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton55 = new System.Windows.Forms.RadioButton();
            this.tabRadioButton56 = new System.Windows.Forms.RadioButton();
        



        
          
         
 
        

           
















            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.tabPage3 = new System.Windows.Forms.TabPage();
            this.tabPage4 = new System.Windows.Forms.TabPage();
         

            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.tab1Label1 = new System.Windows.Forms.Label();
            this.tab1Button1 = new System.Windows.Forms.Button();
    

            this.tab3RadioButton2 = new System.Windows.Forms.RadioButton();

            this.tab3RadioButton1 = new System.Windows.Forms.RadioButton();

            this.tabControl1.SuspendLayout();
            this.SuspendLayout();
            //
            // tabControl1
            //

      
   
    
   
            tabPage1.Controls.Add(this.tab2CheckBox1);
            tabPage2.Controls.Add(this.tab1Label1);
            tabPage2.Controls.Add(this.tab1Button1);

            tabPage3.Controls.Add(this.tab3RadioButton2);
            tabPage3.Controls.Add(this.tab3RadioButton1);
       
//design of all the controls did not provide coz lack of space


        
         
            this.Name = "Form1";
            this.Text = "TabPages";
            this.tabControl1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void tab1Button1_Click(object sender, System.EventArgs e)
        {
            // Inserts the code that should run when the button is clicked.
        }
    
        void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            if (e.TabPage != null)
            {
                if (_cache.Contains(e.TabPage))
                {
                    _cache.Remove(e.TabPage);




                }

                _cache.Add(e.TabPage);


            }

       
 


        }
   

        private void button1_Click(object sender, EventArgs e)
        {



      

                TabPage page = new TabPage("TabPage" + pageNumber.ToString());






                AddControlsToTabPage(page);


                this.tabControl1.TabPages.Add(page);
              
           
         
            pageNumber++;
          
           this.tabControl1.SelectedTab = page;
           

         
      

        }

   
          
          


    
        


        private void AddControlsToTabPage(TabPage page)
        {


            page.Controls.Add(this.tab1CheckBox1);
            page.Controls.Add(this.tabCheckBox2);
            page.Controls.Add(this.tabCheckBox3);
            page.Controls.Add(this.tabCheckBox4);
            page.Controls.Add(this.tabCheckBox5);
            page.Controls.Add(this.tabCheckBox6);
            page.Controls.Add(this.tabCheckBox7);
            page.Controls.Add(this.tabCheckBox8);
            page.Controls.Add(this.tabCheckBox9);
            page.Controls.Add(this.tabCheckBox10);
            page.Controls.Add(this.tabCheckBox11);
            page.Controls.Add(this.tabCheckBox12);
            page.Controls.Add(this.tabCheckBox13);
            page.Controls.Add(this.tabCheckBox14);
            page.Controls.Add(this.tabCheckBox15);
            page.Controls.Add(this.tabCheckBox16);
            page.Controls.Add(this.tabCheckBox17);
            page.Controls.Add(this.tabCheckBox18);
            page.Controls.Add(this.tabCheckBox19);
            page.Controls.Add(this.tabCheckBox20);
            page.Controls.Add(this.tabCheckBox21);
            page.Controls.Add(this.tabCheckBox22);
            page.Controls.Add(this.tabCheckBox23);
            page.Controls.Add(this.tabCheckBox24);
            page.Controls.Add(this.tabCheckBox25);
            page.Controls.Add(this.tabCheckBox26);
            page.Controls.Add(this.tabCheckBox27);
            page.Controls.Add(this.tabCheckBox28);
            page.Controls.Add(this.tabCheckBox29);
            page.Controls.Add(this.tabCheckBox30);
            page.Controls.Add(this.tabCheckBox31);
            page.Controls.Add(this.tabCheckBox32);
            page.Controls.Add(this.tabCheckBox33);
            page.Controls.Add(this.tabCheckBox34);
            page.Controls.Add(this.tabCheckBox35);
            page.Controls.Add(this.tabCheckBox36);
            page.Controls.Add(this.tabCheckBox37);
            page.Controls.Add(this.tabCheckBox38);
            page.Controls.Add(this.tabCheckBox39);
            page.Controls.Add(this.tabCheckBox40);
            page.Controls.Add(this.tabCheckBox41);
            page.Controls.Add(this.tabCheckBox42);

            page.Controls.Add(this.tabCheckBox43);
            page.Controls.Add(this.tabCheckBox44);        

           
         
            page.Controls.Add(this.tabRadioButton);
       
            page.Controls.Add(this.tab1Radio1Button1);

            page.Controls.Add(this.tab2Radio2Button2);
            page.Controls.Add(this.tab3Radio3Button3);
            page.Controls.Add(this.tab4Radio4Button4);
            page.Controls.Add(this.tab5Radio5Button5);
            page.Controls.Add(this.tab6Radio6Button6);
            page.Controls.Add(this.tab7Radio7Button7);
            page.Controls.Add(this.tab8Radio8Button8);
            page.Controls.Add(this.tab9Radio9Button9);
            page.Controls.Add(this.tab10Radio10Button10);
            page.Controls.Add(this.tab11Radio11Button11);
            page.Controls.Add(this.tab12Radio12Button12);
            page.Controls.Add(this.tab13Radio13Button13);
            page.Controls.Add(this.tab14Radio14Button14);
            page.Controls.Add(this.tabRadioButton15);
            page.Controls.Add(this.tabRadioButton16);
            page.Controls.Add(this.tabRadioButton17);
            page.Controls.Add(this.tabRadioButton18);
            page.Controls.Add(this.tabRadioButton19);
            page.Controls.Add(this.tabRadioButton20);
            page.Controls.Add(this.tabRadioButton21);
            page.Controls.Add(this.tabRadioButton22);
            page.Controls.Add(this.tabRadioButton23);
            page.Controls.Add(this.tabRadioButton24);
            page.Controls.Add(this.tabRadioButton25);
            page.Controls.Add(this.tabRadioButton26);
            page.Controls.Add(this.tabRadioButton27);
            page.Controls.Add(this.tabRadioButton28);
            page.Controls.Add(this.tabRadioButton29);
            page.Controls.Add(this.tabRadioButton30);
            page.Controls.Add(this.tabRadioButton31);
            page.Controls.Add(this.tabRadioButton31);
            page.Controls.Add(this.tabRadioButton32);
            page.Controls.Add(this.tabRadioButton33);
            page.Controls.Add(this.tabRadioButton34);
            page.Controls.Add(this.tabRadioButton35);
            page.Controls.Add(this.tabRadioButton36);
            page.Controls.Add(this.tabRadioButton37);
            page.Controls.Add(this.tabRadioButton38);
       
            page.Controls.Add(this.tabRadioButton40);
            page.Controls.Add(this.tabRadioButton41);
            page.Controls.Add(this.tabRadioButton42);
            page.Controls.Add(this.tabRadioButton43);
            page.Controls.Add(this.tabRadioButton44);
            page.Controls.Add(this.tabRadioButton45);
            page.Controls.Add(this.tabRadioButton46);
            page.Controls.Add(this.tabRadioButton47);
            page.Controls.Add(this.tabRadioButton48);
            page.Controls.Add(this.tabRadioButton49);
            page.Controls.Add(this.tabRadioButton50);
            page.Controls.Add(this.tabRadioButton51);
            page.Controls.Add(this.tabRadioButton52);
            page.Controls.Add(this.tabRadioButton53);
            page.Controls.Add(this.tabRadioButton54);
            page.Controls.Add(this.tabRadioButton55);
            page.Controls.Add(this.tabRadioButton56);




    

        }


       
         
         






   




     




        private void button2_Click(object sender, EventArgs e)
        {
            if (_cache.Count > 0)
            {


                this.tabControl1.Selected -= new TabControlEventHandler(tabControl1_Selected);

                this.tabControl1.TabPages.Remove(_cache[_cache.Count - 1]);


                this.tabControl1.Selected += new TabControlEventHandler(tabControl1_Selected);


              

                _cache.RemoveAt(_cache.Count - 1);

            }


            if (_cache.Count > 0)
            {
              
                this.tabControl1.SelectedTab = _cache[_cache.Count - 1];
            }


        



        }      



    }
}

Now problem with my program is that i have 100 controls added to tabpages ,when i click on add button

I add the tabpages with these 100 controls but only the last tabpage has these 100 controls when i

open the previous added tabpages they are empty.But, noe i want the functinality in such a way that

suppos i add  infinite tabpages all those tabpages should have these same 100 controls when i open

the added tabpages, that is i need to add controls to tabpages while creating it.If u ar not clear with my requirement pls let

me know.I am going in loops i need to

 find a solution to my problem pls help me out.Well, i  have to find a way to add controls to the tab page wile creating tabpage.

So how do i do that can u pls help me.

Thanks in advance


  Santhosh N replied to swapna moturu
17-Mar-09 05:07 AM

How about creating a User control or custom control for this requirement as you are saying you need to have same set of 100 controls in each tab page...

If I understand this correctly, this would be a better approach than adding in a loop..

Please let me know your thought and revert if not possible

Use ParentControl.Controls.Add method  Use ParentControl.Controls.Add method

17-Mar-09 05:30 AM
control       Parent
Tabcontrol    Form
Tabpage       Tabcontrol  
Controls      Tabpage
Just paste this code in a button click event of a winform application, to know how this works.
TabControl tb = new TabControl();

            TabPage tp1=new TabPage("1");
            TabPage tp2=new TabPage("2");
            TabPage tp3=new TabPage("3");
            TabPage tp4=new TabPage("4");

            Label lbl1 = new Label();
            RadioButton rb = new RadioButton();

            tp1.Controls.Add(lbl1);
            tp1.Controls.Add(rb);

            tb.Controls.Add(tp1);
            tb.Controls.Add(tp2);
            tb.Controls.Add(tp3);
            tb.Controls.Add(tp4);

            this.Controls.Add(tb);

adding controls to tabpages in c# using ado.net  adding controls to tabpages in c# using ado.net

17-Mar-09 06:07 AM
Thanks for the response Sathish S .But this i have already applied my problem is when i have "infinite tabpages"

added i need to add same "50 Controls" to all the tabpages that is, every time when i add tabpages ineed to add these same 50 controls to all these tabpages and when i open these added tabpages i should  have these same fifty

controls.If u ar not clear pls let me know

Thanks in advance
adding controls to tabpages  adding controls to tabpages
17-Mar-09 06:47 AM
Thanks for the response Santhosh Kappa.But my problem is when i have "infinite tabpages"

added i need to add same "50 Controls" to all the tabpages that is, every time when i add tabpages ineed to add these same 50 controls to all these tabpages and when i open these added tabpages i should  have these same fifty

controls.If u ar not clear pls let me know. Anyways, how about putting the 100 controls in a single collection List<Control>, for example, and in form Load event (for example) iterate over the tabpages and add all the controls for each tabpage.
Or even better create a custom control or a custom tabpage to hold the controls you want and add this control or page to all the tabpages you want,i have this idea but unable to implement it programatically according to my program.So can u pls help me out in sending a sample according to my program

Thanks in advance
  Santhosh N replied to swapna moturu
17-Mar-09 06:55 AM

Swapna,

first of all I am santhosh Kapa not Kappa :)

I was saying you to create a user control with just controls in a template and add this instance( User control with just controls) onto the tab page inside a loop depending on the number of tab pages to be created...

Your other idea is quite good if you dont want to use user control but wanted to go with List..But its quite difficult considering the maintainability of the code...if needed to think if it matters though..

adding controls to tabpages  adding controls to tabpages
17-Mar-09 07:19 AM
Thanks for ur response santhosh kapa.

Sorry for wrong typing ur name.The first approach given by u will work out i guess .But i ve created a user control

and added all the controls to it. But i am having the problem with writing he loop.With my loop i am  getting the

tabpages but no controls added to it.So can u send me a code according to my program so that i can

execute it directly.Ive already tried alot but not geting the right thing needed so ,pls help me out.


Thanks in advance
  Santhosh N replied to swapna moturu
17-Mar-09 07:28 AM

Never mind :)

It should be a small change I guess..

Are you first creating a tabpage and adding the user control to it and then adding to the collection of tabpages...(in the loop)

If you follow this it should work for you...

Can you let me know if it works or otherwise I ll ttry to send you sample after I find some time to work on it...

adding controls to tabpages  adding controls to tabpages
17-Mar-09 08:02 AM
  Thanks for ur response santhosh kapa
  public partial class Form1 : Form
    {

        private static int pageNumber=4;
        private TabPage page = new TabPage();


 private void button1_Click(object sender, EventArgs e)
        {



            for (int i = 0; i < pageNumber; i++)
            {

                page = new TabPage("TabPage" + pageNumber.ToString());


            



                AddControlsToTabPage(page);


                this.tabControl1.TabPages.Add(page);

                this.tabControl1.SelectedTab = page;
            
            }
          


     
       

        }
As u have already seen my program i ahve three tabpages as default so when i add the next time by clicking the

 add button i have to get tabpage 4 with the user control (50 to 100 controls) and when i click the add button

again i need to get tabpage 5 with the user control(50 to 100 controls).But with my above logic everytime click

i click on the add button i get 4 tabpages named "tabpage 4" with the controls added to the last tabpage ,when

i open the prevous added tabpages they are empty only the last tabpage will have those controls.

But my problem is while clicking the add button i need to get tappage 4 with the same 50 controls

then again click on the add button i need to get tabpage 5 with thos e same 50 controls and so on ...I f u ar not

clear with my requirement pls let me know.And if u ar free pls tell me wat all changes i have to do coz i am stuked out.

Thanks in advance







  Santhosh N replied to swapna moturu
17-Mar-09 09:24 AM

I suspect the problem to be in the

AddControlsToTabPage(page);

here in this method you are adding the controls of the existing page...

Try to add a new control and add that control to the page collection of controls and check..

 

adding controls to tabpages  adding controls to tabpages
18-Mar-09 01:09 AM
Thanks for ur response santhoshKapa i need to add 50 to 100 controls but each time i  add  a new 100

controls then it will be very time taking . I want the same 100 controls to be added to all the tabpages and how do

i add that control to the page collection of controls.


Thanks in advance
  Santhosh N replied to swapna moturu
18-Mar-09 02:31 AM

Swapna,

You can not add the controls to the tabpage which are the controls added to the form...

You need to create new controls for the tabpage...

Here is a sample to replicate what I am saying

private void button1_Click(object sender, EventArgs e)

{

TabPage tb1 = new TabPage();

tb1.Controls.Add(textBox1); //TextBox of form1

tb1.Controls.Add(textBox2); //TextBox of form1

TextBox t1 = new TextBox(); //New TextBox created

t1.Text = "t1";

tb1.Controls.Add(t1);

tabControl1.TabPages.Add(tb1);

}

In the above code, you could see a new tabpage created with only one textbox added which is the new textbox...

I would suggest you to go with user control for this to solve the overhead of creating new controls for every page

adding controls to tabpages  adding controls to tabpages
18-Mar-09 03:18 AM
Thanks santhosh kapa
its working  excelently but a small problem, i am able to add only one control when i am adding another controls i

am unable to get that control.

this is wat ive done
    private void button1_Click(object sender, EventArgs e)
        {



     

            page = new TabPage("TabPage" + pageNumber.ToString());






        


            TextBox t1 = new TextBox(); //New TextBox created

            t1.Text = "t1";

            CheckBox cb = new CheckBox();// New check box created
            cb.Text = "cb";
        
          

            page.Controls.Add(t1);
            page.Controls.Add(cb);
      

            tabControl1.TabPages.Add(page);


             this.tabControl1.SelectedTab = page;


        
            pageNumber++;


   


        }

i am getting a text box in each and every tabpage added but no check box how do i implement it(Actually i

need to implement 50 to 100 controls)  .Can u please help me .

Thanks Onceagain for helping me out

  Santhosh N replied to swapna moturu
18-Mar-09 05:17 AM

Hmm...

Interesting!!

You know what, You need to set the Left and Bottom properties for each control to make it visible in tab control...

Debugging I saw the control collection intact but the problem is all being painted in the same location..

Thats the real issue..(For your reference, check this)

TabPage tb1 = new TabPage();

tb1.Controls.Add(textBox1); //TextBox of form1

tb1.Controls.Add(textBox2); //TextBox of form1

TextBox t1 = new TextBox(); //New TextBox created

t1.Text = "t1";

t1.Left = 80;

tb1.Controls.Add(t1);

CheckBox cb = new CheckBox();// New check box created

cb.Text = "cb";

cb.Left = 10;

tb1.Controls.Add(cb);

tabControl1.TabPages.Add(tb1);

adding controls to tabpages  adding controls to tabpages
18-Mar-09 06:50 AM
Thanks for ur response santhosh kapa.

but still i do face a problem private void button1_Click(object sender, EventArgs e)
        {


      

         TabPage page = new TabPage("TabPage" + pageNumber.ToString());




         //TextBox t1 = new TextBox(); //New TextBox created

         //t1.Text = "t1";
         //t1.Left = 80;
      
         //page.Controls.Add(t1);

         CheckBox cb = new CheckBox();// New check box created
         cb.Text = "cb";

         cb.Left = 10;

         page.Controls.Add(cb);

         CheckBox cbe = new CheckBox();// New check box created
         cbe.Text = "cbe";
         cbe.Left =150;
         page.Controls.Add(cbe);

         CheckBox cb1 = new CheckBox();// New check box created
         cb1.Text = "cb1";
         cb1.Left = 290;

         page.Controls.Add(cb1);


         CheckBox cb2 = new CheckBox();// New check box created
         cb2.Text = "cb2";
         cb2.Left = 430;

         page.Controls.Add(cb2);

         CheckBox cb3 = new CheckBox();// New check box created
         cb3.Text = "cb3";
         cb3.Left = 570;

         page.Controls.Add(cb3);

         CheckBox cb4 = new CheckBox();// New check box created
         cb4.Text = "cb4";
         cb4.Left = 710;

         page.Controls.Add(cb4);

         CheckBox cb5 = new CheckBox();// New check box created
         cb5.Text = "cb5";
         cb5.Left = 850;

         page.Controls.Add(cb5);


         CheckBox cb6 = new CheckBox();// New check box created
         cb6.Text = "cb6";
         cb6.Left = 990;

         page.Controls.Add(cb6);
       


         tabControl1.TabPages.Add(page);


         this.tabControl1.SelectedTab = page;



         pageNumber++;


     }
This is the  code in the add button functionalty  when u execute it with my main code u will understand my

functionality.Now ,the problem is while adding the tabpages i am geting 8 checkboxes as ive declared but below that i

want to give textboxes, radio buttons various controls but how do i set the design properties(I need to add about 50

 to 100 controls)

actualy after these check boxes i wanted to have textboxes but  when i did this
as u said ive used the bottom property and even right but not working
TextBox t1 = new TextBox(); //New TextBox created

         t1.Text = "t1";
         t1.Bottom = 2000;
      
         page.Controls.Add(t1);

or

TextBox t1 = new TextBox(); //New TextBox created

         t1.Text = "t1";
         t1.right = 2000;
      
         page.Controls.Add(t1);



I am geting a build error like this
Error    1    Property or indexer 'System.Windows.Forms.Control.Bottom' cannot be assigned to -- it is read
only

Only with the left design property its working how do i implemnt the design of other controls.I f u execute my

program u will understand it.This is thing is really driving me nuts please help me out

Thanks in advance

  




  

        

         
       
  Santhosh N replied to swapna moturu
18-Mar-09 07:11 AM

Hmm...

Try with Top property instead of Bottom property and this is the problem working with many controls..you need to really drive nuts to make the design looks perfect and its possible only with many tries....

I still recommend you to go with a user control just to avoid these maintainability and performance issues and now this design issue too

Anyway, If you still did not succeed, please send me the whole proj so that I can have a look

santhosh[dot]kapa  in the gmail

adding controls to tabpages  adding controls to tabpages
18-Mar-09 08:11 AM
Thanks santhosh kapa u have  been very helpful to me in solving my problem.

Atlast i did solve my problem its just that  t1.Location = new Point(30,30) this is a sample .

Rest, i have designed  all the controls in the location i wanted.


Thanks u once again to be very patient and helpful to me.
cheers!!!  cheers!!!
18-Mar-09 10:38 AM
U r welcome!
Create New Account
help
RichTextBox , HScrollBar , VScrollBar none none none none none none none none none none Button , CheckBox , RadioButton Click Click, Click none none none none none none none none ListBox , CheckedListBox , ComboBox Click Click Click Click, Click Form , DataGrid , Label , LinkLabel , Panel , GroupBox , PictureBox , Splitter , StatusBar , ToolBar , TabPage , * * TabControl Click Click, DoubleClick Click Click, DoubleClick Click Click, DoubleClick Click Click, DoubleClick Click Click, DoubleClick all you can write code in button double click event private void Button1_DoubleClick(Object sender, EventArgs e) { / / your code } refer this for more button double click event http: / / msdn.microsoft.com
included a method which works exactly how I wish for a 1 tabpage within a tabcontrol. The other tabpages within this tabcontrol function in exactly the same way, the only difference is the actual label text between be inherited by all the tabpages? It would save me having to replace all the radiobutton names etc. I have tried Radiobutton.checked but this does not seem to be the way to make the method check any radiobutton. Any help or where to look would be greatly appreciated. private void Tabpage1CheckChanged( object sender EventArgs e) { if (radioButton170.Checked) { panel115.Enabled = true ; } else { panel115.Enabled = false ; } if (radioButton171.Checked) { tabControl2 in panel118.Controls) { foreach (Control ctrl2 in panel117.Controls) { foreach (Control ctrl3 in panel116.Controls) { RadioButton radio = ctrl1 as RadioButton; RadioButton radio2 = ctrl2 as RadioButton; RadioButton radio3 = ctrl3 as RadioButton; if (radio.Checked) { if (radio2
object sender, DataListCommandEventArgs e) { if (String.Equals(e.CommandName, "Validate")) { DataListItem dataItem = (DataListItem)e.Item; RadioButton rbtn1 = (RadioButton)dataItem.FindControl("RadioButton1"); RadioButton rbtn2 = (RadioButton)dataItem.FindControl("RadioButton2"); RadioButton rbtn3 = (RadioButton)dataItem.FindControl("RadioButton3"); RadioButton rbtn4 = (RadioButton)dataItem.FindControl("RadioButton4"); Label ans = (Label)dataItem.FindControl("Label4"); Image rt = (Image)dataItem.FindControl("Image1
How to use the radiobutton in WPF and XAML. How to use the radiobutton in WPF and XAML. Title: How to use the radiobutton in WPF and XAML. WPF RadioButton Control: RadioButton controls are usually grouped together to offer user a single choice among several options (only one button at a time can be selected). <RadioButton> < / Radiobutton> tag is used too create the radio button in XAML. Properties: In the following tag I create the RadioButton in which Height is height of the RadioButton, Name is the nameof the RadioButton, text