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
}










           

Difference between Structure and Union?




STRUCTURE

UNION

1.The keyword  struct is used to define a structure
1. The keyword union is used to define a union.
2. When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum of sizes of its members. The smaller members may end with unused slack bytes.
2. When a variable is associated with a union, the compiler allocates the  memory by considering the size of the largest memory. So, size of union is equal to the size of largest member.
3. Each member within a structure is assigned unique storage area of location.
3. Memory allocated is shared by individual members of union.
4. The address of each member will be in ascending order This indicates that memory for each member will start at different offset values.
4. The address is same for all the members of a union. This indicates that every member begins at the same offset value.
5 Altering the value of a member will not affect other members of the structure.
5. Altering the value of any of the member will alter other member values.
6. Individual member can be accessed at a time
6. Only one member can be accessed at a time.
7. Several members of a structure can initialize at once.
7. Only the first member of a union can be initialized.