Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Good day all!!! I have a TableLayoutPanel that is designed with two columns and four rows.
 
0 1
1
2
3
 
What I'm trying to do at runtime is to insert a new row between rows 1 and 2 and move the rows below and their contents down, like what happens when you insert new row in excel.
 
I have tried doing this...
 
 
TableLayoutPanel.RowStyles.Insert(2, new RowStyle(SizeType.AutoSize));
TableLayoutPanel.RowCount++;
TableLayoutPanel.Controls.Add(this.label3, 0, 2);
TableLayoutPanel.Controls.Add(this.Exam_Destination, 1, 2);
 
 
But the other controls that are in the TableLayoutPanel below the inserted row just get mixed up.
 
Thanx in advance...
Posted 15-Jan-13 4:41am
azinyama1.1K
Edited 16-Jan-13 4:09am
v3
Comments
Sandeep Mewara at 15-Jan-13 13:09pm
   
And the issue is?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Ive used code similar to this to do functionality like your talking about.
 
Click Event/Method Call
private System.Windows.Forms.ComboBox comboBox;
        private System.Windows.Forms.ComboBox comboBox2;
 
        private void AddRow(int column, int row)
        {
            tblpnl1.RowStyles.Clear();
            tblpnl1.RowStyles.Add(new RowStyle(SizeType.AutoSize, 280F));
            //----------------------
            comboBox = new System.Windows.Forms.ComboBox();
            comboBox.TabIndex = (column * 2) + 1;
            comboBox.Margin = new Padding(0);
            comboBox.Dock = DockStyle.Fill;
            comboBox.Name = "combobox-" + row;
            tblpnl1.Controls.Add(comboBox, column, row);
        }
 
        private void button6_Click(object sender, EventArgs e)
        {
            AddRow(1, 2);
            AddRow(0, 2);
        }</pre>
 

Designer Code
 
//
            // tblpnl1
            //
            this.tblpnl1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
            this.tblpnl1.ColumnCount = 2;
            this.tblpnl1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tblpnl1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tblpnl1.Controls.Add(this.button5, 1, 1);
            this.tblpnl1.Controls.Add(this.button4, 0, 1);
            this.tblpnl1.Controls.Add(this.button3, 1, 0);
            this.tblpnl1.Controls.Add(this.button2, 0, 0);
            this.tblpnl1.Location = new System.Drawing.Point(648, 249);
            this.tblpnl1.Name = "tblpnl1";
            this.tblpnl1.RowCount = 2;
            this.tblpnl1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tblpnl1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tblpnl1.Size = new System.Drawing.Size(548, 168);
            this.tblpnl1.TabIndex = 2;
            //
            // button6
            //
            this.button6.Location = new System.Drawing.Point(1049, 423);
            this.button6.Name = "button6";
            this.button6.Size = new System.Drawing.Size(147, 26);
            this.button6.TabIndex = 3;
            this.button6.Text = "button6";
            this.button6.UseVisualStyleBackColor = true;
            this.button6.Click += new System.EventHandler(this.button6_Click);
            //
            // button2
            //
            this.button2.Location = new System.Drawing.Point(4, 4);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(147, 26);
            this.button2.TabIndex = 2;
            this.button2.Text = "button2";
            this.button2.UseVisualStyleBackColor = true;
            //
            // button3
            //
            this.button3.Location = new System.Drawing.Point(277, 4);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(147, 26);
            this.button3.TabIndex = 3;
            this.button3.Text = "button3";
            this.button3.UseVisualStyleBackColor = true;
            //
            // button4
            //
            this.button4.Location = new System.Drawing.Point(4, 87);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(147, 26);
            this.button4.TabIndex = 4;
            this.button4.Text = "button4";
            this.button4.UseVisualStyleBackColor = true;
            //
            // button5
            //
            this.button5.Location = new System.Drawing.Point(277, 87);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(147, 26);
            this.button5.TabIndex = 5;
            this.button5.Text = "button5";
            this.button5.UseVisualStyleBackColor = true;
  Permalink  
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid