Naren Shukla
Naren Shukla

Reputation: 35

Groupbox in winform is not getting Refreshed

I have a groupbox which is containing controls like Textboxes,Lables,Comboboxes etc.Now i want to refresh this groupbox on button click.Here is the Codes that i am executing on button click but the refreshing is not happening in the 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 !");
    }

Please help me..

Upvotes: 0

Views: 854

Answers (1)

prem
prem

Reputation: 3548

Refresh don't update the values. To update the values set the updated values in the groupbox again.

Here's a sample to help you

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);
    }
}

Upvotes: 1

Related Questions