I'm trying to create a list of buttons and a list of textboxes, and I need to interact between these elements. I mean, whenever I click on the button, I need to do some action with the textbox in the same line. I tried to use delegate on the click event, but I can't really find a way to point the textbox I want to target.
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true;
openFileDialog.ShowDialog();
string[] files = openFileDialog.FileNames.ToArray();
int index = 0;
List<Button> EditButtons = new List<Button>();
List<TextBox> TextBoxes = new List<TextBox>();
foreach (var file in files)
{
EditButtons.Add(new Button() { Text = "Edit", Top = index +50, Left = 150 });
TextBoxes.Add(new TextBox() { Text = file, Top = index +50, Left = 5 });
index = index + 25;
}
foreach (Button button in EditButtons)
{
Controls.Add(button);
}
foreach (TextBox textBox in TextBoxes)
{
Controls.Add(textBox);
}
}