Thursday 5 November 2015

How to Dynamically create Multiple Tabpages with Gridview in Each Tab on Button click


Below is the code how to Dynamically create Multiple Tabpages with Gridview in Each Tab.



private void btn_new_Click(object sender, EventArgs e)
        {
       

//For creating the Headers such as name ,values,class


            DataGridViewTextBoxColumn Name = new DataGridViewTextBoxColumn();
            Name .HeaderText = "Name";
            Name .Width = 150;

 DataGridViewTextBoxColumn values= new DataGridViewTextBoxColumn();
            values.HeaderText = "values";
            values.Width = 150;

 DataGridViewTextBoxColumn class= new DataGridViewTextBoxColumn();
            class.HeaderText = "Class";
            class.Width = 150;

 DataGridViewTextBoxColumn  Time = new DataGridViewTextBoxColumn();
            Time  .HeaderText = "Time";
            Time .Width = 150;

 DataGridViewTextBoxColumn A = new DataGridViewTextBoxColumn();
            A .HeaderText = "A";
            A .Width = 150;


 DataGridViewTextBoxColumn  B = new DataGridViewTextBoxColumn();
            B .HeaderText = "B";
            B .Width = 150;


//now add tab page in main tab.


          TabPage tabpage = new TabPage(class_new_tab.new_tab_name_returned);
            tabpage.BackColor = Color.White;
            tabpage.Name = class_new_tab.new_tab_name_returned;
            tabpage.Width = 200;
            tabpage.Height = 20;

           Tab.Controls.Add(tabpage);


// now add gridview ,this gridview you have to add in tab page..


             DataGridView dgv = new DataGridView();
            dgv.Dock = DockStyle.Fill;
            dgv.BackgroundColor = Color.White;
            tabpage.Controls.Add(dgv);
            dgv.Columns.Add(Name);
            dgv.Columns.Add(values);
            dgv.Columns.Add(class);
            dgv.Columns.Add(Time);
           dgv.Columns.Add(A);
            dgv.Columns.Add(B);
            dgv.RowHeadersVisible = false;//this will hide header from gridview
}










           

0 comments:

Post a Comment