我尝试根据How do I pass a value from a child back to the parent form?
尝试执行此代码但是,我只想将日期值传递给MDI Mainform,其功能是它将加载datagridview中的所有数据(在主窗体中) 儿童表格是ShowDialogue
主要MDI表格父母,在儿童表格对话结束后,其值为"日期"将Date Value Child获取到显示数据的函数时,将刷新datagridview上的数据。
很抱歉这个混乱,因为我最终在这里问。
答案 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选项是
创建一个静态类并将其属性值分配给您的日期,并从父表单中获取日期值。