Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear

I want to add new row in table layout panel with existing rows.I tried the following code.It didn't work. it works but not adding the rows at the end of the existing row. I want, if user click the last text box in a row the new row will generate automatically after that row.please help
C#
tableLayoutPanel2.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
            tableLayoutPanel2.AutoSize = true;

            int InsertRowNum = tableLayoutPanel2.RowCount;
            int InsertColumnNum = tableLayoutPanel2.ColumnCount;
            tableLayoutPanel2.AutoScroll = true;
            tableLayoutPanel2.Visible = true;

            RowStyle newRowStyle = new RowStyle();
            newRowStyle.SizeType = SizeType.Absolute;
            newRowStyle.Height = 30;
            tableLayoutPanel2.RowStyles.Insert(InsertRowNum, newRowStyle);

            tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(SizeType.Absolute, 30));
             //Add controls to the new row
            tableLayoutPanel2.Controls.Add(textBox1, InsertRowNum + 1, 0);
            tableLayoutPanel2.Controls.Add(textBox1, InsertRowNum, 1);
            tableLayoutPanel2.Controls.Add(comboBox1, InsertRowNum, 2);
            tableLayoutPanel2.Controls.Add(comboBox1, InsertRowNum, 3);



            for (int row = tableLayoutPanel2.RowCount; row <= tableLayoutPanel2.RowCount; row++)
            {
                for (int column = 0; column < tableLayoutPanel2.ColumnCount - 2; column++)
                {
                    TextBox textBox = new TextBox();
                    textBox.Text = string.Format("", column, row);
                    tableLayoutPanel2.Controls.Add(textBox3, 5, 0);
                }

            }


            //tableLayoutPanel2.TabIndex++;
           tableLayoutPanel2.Visible = true;
        }
Posted
Updated 26-Jun-12 2:00am
v2

To add a new row to your table layout panel you should do:
C#
tableLayoutPanel2.RowCount += 1;
 
Share this answer
 
 
Share this answer
 
I designed a single row and some columns with TableLayoutPanel. In each Columns i put some controls mainly textboxes and at the last Column a "+" button.
After entering some data in each textboxes and finally clicking the "+" Button,
a new row must be generated showing the entered data.
Help Pls....
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900