如何在运行时在tablelayoutpanel中添加新行 [英] how to add new row in tablelayoutpanel at runtime

查看:158
本文介绍了如何在运行时在tablelayoutpanel中添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的



我想在现有行的表布局面板中添加新行。我尝试了以下代码。它没有用。它可以工作,但不会在现有行的末尾添加行。我想,如果用户单击行中的最后一个文本框,新行将在该行之后自动生成。请帮助

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

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;
        }

推荐答案

要在表布局面板中添加新行,您应该这样做:

To add a new row to your table layout panel you should do:
tableLayoutPanel2.RowCount += 1;


此链接可能有帮助!



在运行时向TableLayoutPanel添加行 [ ^ ]
This link might help!

Add rows to a TableLayoutPanel at run-time [^]


我设计了一行和一些列使用TableLayoutPanel。在每个列中,我将一些控件主要放在文本框中,在最后一列放置一个+按钮。

在每个文本框中输入一些数据后最后单击+按钮,
$ b必须生成显示输入数据的$ ba新行。

帮助请....


这篇关于如何在运行时在tablelayoutpanel中添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆