Ich habe 2 Formulare namens BillingForm (übergeordnetes Formular) und SearchProduct (untergeordnetes Formular).Wie übergibt man den Wert vom untergeordneten Formular zum übergeordneten Formular?
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();
}
}
Ich erhalte eine Fehlermeldung.
Eine nicht behandelte Ausnahme des Typs ‚System.InvalidCastException‘ aufgetreten in BillingSoftware.exe
Zusätzliche Informationen: Kann nicht das Objekt des Typs ‚BillingForm.MDIParent‘ werfen ‚eingeben BillingForm.BillingForm
Mögliche Duplikat [Wie gebe ich einen Wert von einem Kind zurück in die übergeordnete Formular?] (http://stackoverflow.com/questions/280579/how -do-i-pass-a-Wert-from-a-Kind-Back-to-the-Eltern-für m) – itsme86
@ itsme86 Ich habe diese Codierung gesehen. Ich habe nur die gleiche Codierung verwendet. Aber ich bekomme eine Ausnahme. Bitte beachten Sie meine Fehlermeldung – Faisal
Ist BillingForm ein MDI-Formular? – itsme86