I have a TableLayoutPanel where user adds new rows at runtime. This rows can contain Labels, textboxes, buttons and other TableLayoutPanels with controls. I need to handle the events of this inner controls. Can anyone explain how?
Here is what I tried:
private void AddStringRowFilter()
{
Button bt = new Button();
bt.Click += Bt_Click;
filtersLayoutTable.Controls.Add(bt, 0, filters);
Label l1 = new Label();
l1.Text = filtersComboBox.SelectedText + ":";
filtersLayoutTable.Controls.Add(l1, 1, filters);
}
private void Bt_Click(object? sender, EventArgs e)
{
MessageBox.Show("Button working!");
}
private void addFilterButton_Click(object sender, EventArgs e)
{
AddStringRowFilter();
if (filters == 0) { OnHasFilters(EventArgs.Empty); }
filters++;
if (filters == maxFilters) { addFilterButton.Enabled = false; }
}
I expected to see the MessageBox here. What type of rows I actualy wanted to add is that I designed below:
P.S. Sorry for my bad english, I guess.
New contributor
NIK303 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.