I have 2 forms called BillingForm(parent form) and SearchProduct(child form).
BillingForm code
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 form code (Child Form)
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();
}
}
I am getting an error message.
An unhandled exception of type 'System.InvalidCastException' occurred in BillingSoftware.exe
Additional information: Unable to cast object of type 'BillingForm.MDIParent' to type 'BillingForm.BillingForm