Hi All,
I've come accross a problem, that is probably seen pretty often, but has never really been discussed here.
In my Gui, I'm adding Controls in a for loop to a Flowpanellayout. The point is to display "reports" from a database. It has to be dynamic, because the number of reports can be different from day to day.
Pseudocode Adding Gui Elements:
for(int i = 0; i < reports.Count; i++)
{
TextBox textboxPerson = new TextBox();
textboxPerson.Name = "TextboxName" + i;
textboxPerson.Text = reports[i].Name;
textboxPerson.TextChanged += new EventHandler(this.textboxPerson_TxtChanged);
Label labelToChange = new Label();
labelToChange.Name = "label"+i;
labelToChange.Text = "";
flowlayoutPanel.Controls.Add(textboxPerson);
flowlayoutPanel.Controls.Add(labelToChange);
}
Event Handler:
private void textboxPerson_TextChanged(object sender, EventArgs e)
{
//So far, I'm only getting the number of the Textbox that changed.
}
Here is, where I need your advise. The Textboxs and Labels are matching (iE, Texbox1 is as you can see connected to Label1). But how do I adress one Control in particular?
- If Texbox1's Text changes, how do I address Label1 to change its Text or something?
- Is there a state of the art of adding dynamic Gui Elements to a Form and handling them?
Thank you for your answers