0

Hi!,

I get InvalidCastException.
It says "Unable to cast object of type 'HD.MainMenu' to type 'HD.NewBookEntry'" and points to this statment "mpg=(NewBookEntry)fm"
Plz help me to solve this.
My code is:

FormCollection fms=Application.OpenForms;
            foreach(Form fm in fms)
            {
                mpg=(NewBookEntry)fm;
            }
            mpg.Dispose();
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by coroll
0

Form has a public Dispose() method. Why are you trying to cast between the two types? Assuming that both classes derive from Form, HD.MainMenu and HD.NewBookEntry are both ancestors of Form, and have common variables/methods from Form. However, they define their own variables/methods, therefore they lack a commonality between them.

0

I figured it out.

Form2 nbe = (Form2)Application.OpenForms["Form2"];

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.