将行插入TableLayoutPanel C#4.0 [英] Inserting Rows Into TableLayoutPanel C#4.0

查看:90
本文介绍了将行插入TableLayoutPanel C#4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!我有一个TableLayoutPanel设计有两列四行。



0 1

1

2

3



我在运行时尝试做的是在第1行和第2行之间插入一个新行并移动行下面和它们的内容下来,就像你在excel中插入新行时会发生什么。



我试过这样做...



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





但是插入行下面的TableLayoutPanel中的其他控件只是混合了up。



提前使用Thanx ...

解决方案

我用过与此类似的代码来做功能就像你在谈论。



点击事件/方法调用

  private  System.Windows.Forms.ComboBox comboBox; 
private System.Windows.Forms.ComboBox comboBox2;

private void AddRow( int 列, int 行)
{
tblpnl1.RowStyles.Clear();
tblpnl1.RowStyles.Add( new RowStyle(SizeType.AutoSize,280F));
// -------------------- -
comboBox = new System.Windows.Forms.ComboBox();
comboBox.TabIndex =(列* 2 )+ 1 ;
comboBox.Margin = new 填充( 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 >







设计师代码



  //    
// tblpnl1
//
.tblpnl1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle。;
.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 );
.tblpnl1.Name = tblpnl1 ;
.tblpnl1.RowCount = 2 ;
.tblpnl1.RowStyles.Add( new System.Windows.Forms.RowStyle(System .Windows.Forms.SizeType.Percent,50F));
.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( .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 ;


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

解决方案

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;


这篇关于将行插入TableLayoutPanel C#4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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