如何将文本框数组值添加到字符串数组?

问题描述 投票:-1回答:1

如何向字符串[]添加文本框[]值[]

private void button3_Click(object sender, EventArgs e)
{
    string[] text = new string[DT.Columns.Count];
    string[] textb = new string[panel1.Controls.Count];

    // Below is the programmatically textbox

    foreach (Control C in panel1.Controls)
    {
        if (C is TextBox)
        {
            for (int m = 0; m < DT.Columns.Count; m++)
            {

                // This is the place that I want to add the textbox value to string array

                textb[m] = C.Text[m].ToString();
                MessageBox.Show(textb[m]);
            }
        }
    }

    foreach (DataColumn DC in DT.Columns)
    {
        for (int k = 0; k < DT.Columns.Count; k++)
        {
            text[k] = DC.Table.Columns[k].ToString();
        }
    }
c# winforms textbox
1个回答
1
投票

[LINQ非常容易实现。您可以使用:

string[] textb = panel1.Controls
                       .OfType<TextBox>()
                       .Select(t => t.Text)
                       .ToArray();
© www.soinside.com 2019 - 2024. All rights reserved.