简体   繁体   English

我需要在单击按钮时重新加载表单

[英]I need to reload the form on button click

I have been trying different methods these past days to overcome this problem but I haven't found a reliable solution to my problem. 过去几天,我一直在尝试其他方法来克服此问题,但是我没有找到可靠的解决方案。 The problem is I have to reload the form in case the first time the application starts and the components are not filled up due to network or SQL connectivity issue. 问题是我必须重新加载表单,以防应用程序首次启动并且由于网络或SQL连接问题而导致组件未满的情况。 As of now, everyone is closing the application and starting again because the first time they start the application the components were empty. 到目前为止,每个人都在关闭应用程序并重新启动,因为他们第一次启动应用程序时组件为空。

Below is the code I'm using. 下面是我正在使用的代码。

private void Reports_Load(object sender, EventArgs e)
{
    //START:
    try
    {
        RevenueDate_dt = func.getResult(dateQuery);
        foreach (DataRow dr in RevenueDate_dt.Rows)
        {
            comboBox1.Items.Add(dr["Global_Period_Month"].ToString());
        }
    }
    catch (Exception ex)
    {
        //goto START;
        MessageBox.Show("Network is too slow! Please close the application and try again later");
    }
}

Function: 功能:

public DataTable getResult(string query)
{
    //con.Open();
    SqlDataAdapter da = new SqlDataAdapter();
    DataTable dt = new DataTable();
    SqlCommand cmd = new SqlCommand(query, con);
    cmd.CommandTimeout = 0;
    da.SelectCommand = cmd;
    da.Fill(dt);
    return dt;
}

I have placed a retry button on my form so if the first time the component is not filled with the data so everyone can use the retry button to load the component instead of closing the whole application and starting again. 我在表单上放置了一个重试按钮,因此,如果第一次在组件中未填充数据,那么每个人都可以使用重试按钮加载该组件,而不必关闭整个应用程序并重新启动。

You can fill component by calling Reports_Load event in your retry button . 您可以通过在retry button调用Reports_Load event来填充组件。 Reports_Load will fill your component. Reports_Load将填充您的组件。 Check below code. 检查以下代码。

CODE: 码:

private void retry_Click(object sender, EventArgs e)
{
    Reports_Load(null, null);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击按钮通过另一个表单重新加载表单 - Reload a Form through another Form by Button click 点击链接按钮后需要重新加载页面 - Need to reload page after click on link button 当我单击“联系我们”表单的“提交”按钮时。 它会自动转到页面顶部。 但我想重新加载页面的特定部分 - when I click on the submit button of contact us form . it automatically goes to top of the page . but i want to reload specific part of page 重新加载按钮单击 - reload on button click in 在MahApps控件中,在加载表单时会触发验证事件,我需要在单击按钮后显示验证消息 - In MahApps controls Validation Event raises at the time of form Load I need to show Validation Messages after Button click c#点击其他表单提交按钮时,如何重新加载表单? - How to reload form in c# when button submit in another form is click? 从其他表单上的按钮单击事件处理程序刷新控件或重新加载表单 - Refresh the control or reload form from button click event handler on other form 重新加载时再次触发按钮单击 - Button click is again fired on reload 根据按钮属性重新加载按钮单击页面 - reload the page on button click based on button properties 我需要在计时器滴答内的按钮单击对象上使用if语句? - I need to use a if statement on a button click object within a timer tick?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM