I am having trouble figuring out how to handle events for components that are created when I click a button.
I have a class called rows which is used to create a row of components (combo boxes) . I have a button on my form that has an event to create a new rows object. I would like to have events for the newly created combo boxes but I dont know how or where to put them.
Here is my form code:
private void button1_Click(object sender, EventArgs e)
{
rowClass row = new rowClass(startingBuildingComboBoxX, startingRoomComboBoxX, startingProblemsTextBoxX, startingNotesTextBoxX, startingY + 30);
startingY = startingY + 30;
this.Controls.Add(row.buildingComboBox);
this.Controls.Add(row.roomComboBox);
this.Controls.Add(row.problemsTextBox);
this.Controls.Add(row.notesTextBox);
button1.Location = new Point(411, buttonY);
buttonY = buttonY + 30;
this.Height += 30;
}
so whenever I push the button it creates a row of components and also moves the button down to the next row.
I would like to add events for those components that were created in that rows object. But how do I do that??
this is my code for that event:
public void buildingComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
this.roomComboBox.Items.Clear();
if (this.buildingComboBox.SelectedItem.Equals("ATLC"))
{
foreach (int x in ATLC)
{
this.roomComboBox.Items.Add(x);
}
}
}
I just dont know where it belongs, or how to tell the form to use it etc.