【问题标题】:How to reload a form while it asks for parameters?如何在请求参数时重新加载表单?
【发布时间】:2015-02-10 07:23:02
【问题描述】:

我将一个数据集对象传递给我的 form1 的构造函数。现在我需要从form2刷新form1,所以我在form1_load()中写的代码应该更新。但问题是,form1 需要数据集值作为其参数,我在这里不需要任何数据集。只想重新加载form1。

这里是form1(coordinator2)构造函数的代码:

private DataSet _ds = null;
public Coordinator2(DataSet ds)
{
    InitializeComponent();
    _ds = ds;
}

这是我想做的事情:

this.Close();
Coordinator2 cr2 = new Coordinator2(?);
cr2.refresh();

当我编写上面的代码时,它说:Coordinator2 没有任何构造函数,它接受 0 个参数。

【问题讨论】:

  • Coordinator2类的作者是谁? DataSet 是什么意思?如果是可选的,则传递 null。
  • 亲爱的 Sriram,“Coordinator2 的作者”我没听懂你的意思。我发送了包含成功登录的用户配置文件的 Dataset 对象,所以我以多种方式使用了 ds。喜欢欢迎登录用户以及过滤数据等,另一件事是:我已经做了以下事情: Coordinator2 cr2 = new Coordinator2(null); cr2.刷新();但这段代码并没有真正刷新 Coordinator2。因为我在 Coordinator2_load() 事件中写了一些代码,这在 Coordinator2 首次加载时有效,但刷新后没有任何作用。

标签: c# winforms refresh form-load


【解决方案1】:

您可以按照 Sriram 的建议进行操作,然后在尝试创建 Coordinator2 时发送 null

Coordinator2 cr2 = new Coordinator2(null);

或者你可以定义一个可选参数:

public Coordinator2(DataSet ds = null)
{
    InitializeComponent();
    _ds = ds;
}

在这种情况下,如果您不向构造函数发送任何参数,ds 将为空。

【讨论】:

    猜你喜欢
    • 2015-12-10
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多