在VS 2008的运行时向tableLayoutPanel添加行数 [英] add number of rows to tableLayoutPanel at runtime VS 2008

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

问题描述


我想一次在按钮单击上添加一行,并且每次单击都应生成一个新行.
我已经编写了一个代码,但是一次生成了两行.代码如下:-


i want to add one row at a time on button click and on each click a new row should generate.
i have write a code but it generate two rows at a time.the code is as follows:-

private void btnaddrow_Click(object sender, EventArgs e)
        {
            tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
            tableLayoutPanel1.AutoSize = true;

            int InsertRowNum = tableLayoutPanel1.RowCount;
            tableLayoutPanel1.AutoScroll = true;
            tableLayoutPanel1.Visible = true;

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

            tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(SizeType.Absolute, 30));
            // Add controls to the new row
            for (int row = 0; row < tableLayoutPanel1.RowCount; row++)
            {
                for (int column = 0; column < tableLayoutPanel1.ColumnCount; column++)
                {
                    TextBox textBox = new TextBox();
                    textBox.Text = string.Format("TextBox({0}, {1}) ", column, row);
                    tableLayoutPanel1.Controls.Add(textBox, column, row);
                }
                
            }
            

            tableLayoutPanel1.TabIndex++;
            tableLayoutPanel1.Visible = true;


        }

谢谢.

推荐答案

AFAIK,TableLayoutPanel不提供任何操作.

更新:

您无需遍历行和列.只需添加控件,它们将被放置在连续的单元格中.如果需要,面板将自动添加新行.
AFAIK, TableLayoutPanel does not provide anything to do this.

Update:

You do not need to loop through the rows and columns. Just add controls and they will be placed in the consecutive cells. Panel will automatically add new rows if needed.


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

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