在C#中将表单(显示对话)值转换为MDI子表单

时间:2014-05-10 03:45:12

标签: c# desktop-application

我尝试根据How do I pass a value from a child back to the parent form?

尝试执行此代码

但是,我只想将日期值传递给MDI Mainform,其功能是它将加载datagridview中的所有数据(在主窗体中) Child Form which is ShowDialogue 儿童表格是ShowDialogue

Main MDI Form Parent which after the Child Form Dialogue is closed and the data on the datagridview will be refresh 主要MDI表格父母,在儿童表格对话结束后,其值为"日期"将Date Value Child获取到显示数据的函数时,将刷新datagridview上的数据。

很抱歉这个混乱,因为我最终在这里问。

2 个答案:

答案 0 :(得分:1)

您不必在父表单上更新子表单。

相反,在子表单上,创建一个将从DateTimePicker返回值的属性。

public DateTime PurchaseOrderDate
{
    get { return dateTimePicker1.Value; }  // your PO date picker control
}

然后在主窗体上,在子窗体关闭时检索值:

using (mPOrder newPO = new mPOrder())
{
    newPO.ShowDialog();

    var poDate = newPO.PurchaseOrderDate;

    // do something with the date - update grid or whatever
}

答案 1 :(得分:0)

您可以使用以下方法将日期值提供给父表单

您需要在子表单中创建方法是公开的。

public DateTime GetDateFromChild(){
  this.ShowDialog();
return Convert.ToDateTime(this.txtdatevalue.text);

}

在您的父母表格中

childform form = new childform();
Datetime getdate = form.GetDateFromChild();

这未经过测试,但我使用这种方法将值传递给另一个

antoher选项是

创建一个静态类并将其属性值分配给您的日期,并从父表单中获取日期值。