Hi. I'm new to c# and have ran into a problem, I am using the following code to generate textboxes within a panel.
private void button1_Click(object sender, EventArgs e)
{
AddFields();
}
private void AddFields()
{
if (textBoxIndex != 10)
{
TextBox field = new TextBox();
field.Name = "field" + textBoxIndex.ToString();
textBoxIndex++;
field.Size = new Size(200, 20);
panel1.Controls.Add(field);
}
else
{
MessageBox.Show("A Maximum of 10 Areas is Supported");
}
This also caps the textboxes to a maximum of 10, this code works fine for me it is the next bit that I am stuck on. I need to store values entered into each one of the textbox into diffrent variables which I can't do correctly, I am using the following code to find the textbox control.
if (textBoxIndex != 1)
{
}
else
{
Control[] ctrls = Controls.Find("field1", false);
for (int i = 0; i < ctrls.Length; i++)
{
TextBox field1 = (TextBox)ctrls[0];
field1.Text = Variable1;
field1.Text = "";
}
}
I think this is were I have gone wrong and I need help please.