How to add textbox[] value to string[]
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();
}
}
This is very easy to achieve with LINQ . You can just use:
string[] textb = panel1.Controls
.OfType<TextBox>()
.Select(t => t.Text)
.ToArray();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.