2
我有两种形式,称为BillingForm(父窗体)和SearchProduct(子窗体)。如何将值从子窗体传递给父窗体?
BillingForm代码
private void textBoxProductNo_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode==Keys.F9)
{
using(SearchProduct sp=new SearchProduct)
{
sp.ShowDialog(this);
}
}
}
public void updatedText(string fromChildForm)
{
textBoxProduct.text=fromChildForm;
}
SearchProduct形式的代码(子窗体)
private void dataGridView1_KeyDown(object sender,KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
BillingForm bf=(BillingForm)this.Owner; //Error appear here
bf.updatedText("Hello World");
this.close();
}
}
我收到一条错误消息。
“”类型的未处理的异常在BillingSoftware.exe发生
其他信息:无法转换类型“BillingForm.MDIParent”为类型“BillingForm.BillingForm
可能的复制[我如何通过一个数值从孩子回父窗体?](http://stackoverflow.com/questions/280579/how -DO-I-传递一个值从 - 一个孩子背到了父换米) – itsme86
@ itsme86我看到了编码。我只用了相同的编码。但我得到异常。请看我的错误消息 – Faisal
BillingForm是MDI表单吗? – itsme86