0
我想知道如何刪除動態創建的textboxes
和labels
,我想從此事件cmbMethodActions_SelectedIndexChanged
中刪除所有動態創建的textboxes
和labels
。因爲所有textboxes
和labels
都基於數據庫。每個事件都會改變,textboxes
和labels
也會改變。如何在C#Windows窗體中刪除動態創建的文本框和標籤?
截至目前,這裏是我的代碼:
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);
}
}