多个动态创建的列

时间:2018-03-10 04:16:43

标签: c# visual-studio

我正在尝试根据列表中的项目数创建多个动态列。我可以获得生成的行数。我也可以生成所有内容而不是列。最终结果应该是每个列并排,以便我可以逐列选项。前

A    | B    | C    | D
-----+------+------+----
R1 4 | R1 2 | R2 3 | 9

代码:

cavlist = [row1, row2, row3, row4, row5, row6]
attrib = [a,b,c,d]

foreach (string cava in cavlist)
{
    Label lbl = new Label();
    lbl.Text = cava.ToString();
    this.flowLayoutPanel2.Controls.Add(lbl);

    TextBox txtserial = new TextBox();
    txtserial.Name = "cav" + cava;
    txtserial.Width = 100;
    this.flowLayoutPanel2.Controls.Add(txtserial);
}

foreach(String attribs in attrib)
{
    Label label = new Label();
    label.Text = attribs.ToString();

    this.flowLayoutPanel3.Controls.Add(label);

    foreach (string cava in cavlist)
    {
        TextBox txtserial = new TextBox();
        txtserial.Name = "cav" + cava;
        txtserial.Width = 50;
    }
}

1 个答案:

答案 0 :(得分:0)

我最终使用了datagridview

foreach (string attrib in attribs)
        {
            string cat = attrib.ToString();
            dataGridView1.Columns.Add(cat, cat);


        }

        foreach (string cava in cavlist)
        {

            TextBox txtserial = new TextBox();

            dataGridView1.Rows.Add();

        }