winform中的Groupbox没有刷新

时间:2014-09-18 08:15:02

标签: c# .net winforms

我有一个包含文本框,Lables,Comboboxes等控件的groupbox。现在我想在按钮点击时刷新这个组框。这是我在按钮点击时执行的代码但是组框中没有进行刷新。

    try
    {
        //MySqlConnection Mysqlcon = new MySqlConnection();
        MySqlConnection Mysqlcon = new MySqlConnection(connectionString);
        string sql = "DELETE FROM setting WHERE ToMailId='"+emailId+"'";
        Mysqlcon.Open();
        MySqlCommand cmd = new MySqlCommand(sql, Mysqlcon);
        cmd.ExecuteNonQuery();

        Mysqlcon.Close();

        MessageBox.Show("Data Deleted Successfuly");

        groupBox1.Refresh();


    }
    catch
    {
        MessageBox.Show("Data Not! Deleted !");
    }

请帮帮我..

1 个答案:

答案 0 :(得分:1)

刷新不要更新值。 要更新值,请再次在组框中设置更新的值。

以下是帮助您的示例

foreach (Control ctrl in this.Controls) {
    switch (ctrl.GetType) {
        case typeof(TextBox):
            ((TextBox)ctrl).Text = string.Empty;
            break;
        case typeof(ComboBox):
            ((ComboBox)ctrl).Items.Clear();
            break;
        default:
            throw new Exception("This type of control is not handled!!! Need to add a case for type " + ctrl.GetType.ToString);
    }
}
相关问题