我想知道如何删除动态创建textboxes
的和labels
,我想从这个事件中删除所有动态创建的textboxes
和。因为所有的and都是基于数据库的。每个事件都会发生变化,并且也会发生变化。labels
cmbMethodActions_SelectedIndexChanged
textboxes
labels
textboxes
labels
到目前为止,这是我的代码:
private void cmbMethodActions_SelectedIndexChanged(object sender, EventArgs e)
{
GetActionFields(int.Parse(cmbMethodActions.SelectedValue.ToString()));
}
private void GetActionFields(int i)
{
MySqlCommand cmd = new MySqlCommand("call GetActionField("+i+")", cn);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
for (int x = 0; x < dt.Rows.Count; x++)
{
TextBox txtfields = new TextBox();
txtfields.Name = dt.Rows[x]["field_name"].ToString();
txtfields.Width = 175;
flowLayoutPanelText.Controls.Add(txtfields);
Label txtlbl = new Label();
txtlbl.Name = dt.Rows[x]["field_name"].ToString();
txtlbl.Text = txtlbl.Name;
flowLayoutPanelLabel.Controls.Add(txtlbl);
}
}