Click here to Skip to main content
13,347,998 members (54,177 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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
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.Visible = true;
Posted 26-Jun-12 2:58am
Updated 26-Jun-12 3:00am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

To add a new row to your table layout panel you should do:
tableLayoutPanel2.RowCount += 1;
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

Solution 3

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....

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 22 Feb 2014
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100