0

I have a Master Form which contains a Panel and a Couple of Buttons in it.For each button click different forms are loaded into the Panel. one of such form calls another child form on a button click using

ChildForm.ShowDialog(this)

It is a kind of dialog window which accepts a text input from the user, and that needs to updated in one of the control in its parent form.to do this i have a property which sets the input from the user to the control like this

internal String UserInput
{
    get { return UserInput; }
    set 
    {
        label.Text=value;
    }
}

Whenver i try to update the property like below i get an error stating 'System.InvalidCastException'.

((ParentClass)this.Owner).Property= "User Input";

this.owner of the child form shows my master form as its owner even though i send owner details to the child form while calling Showdialog(this).

if am not loading form to the panel everything works fine. Problem occurs only when the forms are loaded to the Panel

Please suggest a solution for this.

Muhammed Shevil KP
  • 1,404
  • 1
  • 16
  • 21
vikas
  • 85
  • 1
  • 5
  • I had a pretty similar problem in the past. One way to solve this is using delegate. Since I'm still not that good at working with them I can't provide you with actual solution but a standard way for sending information between forms is with delegates/events. – Leron Mar 21 '17 at 06:21
  • Without a good [mcve] that reliably reproduces the problem, it's impossible to answer why you get the exception or how to fix it. But, information on how to have a pair of forms interact is available in great number, including in the marked duplicate. You can either pass the parent form reference directly or, better, declare an event the parent form can use for the purpose. – Peter Duniho Mar 21 '17 at 06:43

0 Answers0