Trying to call a method in one form from a different form [resolved]
I have a method in a main form that updates the UI. I am trying to call this method from a different form.
So on my main form, a new form is created
Code:
Dim ScheduleTrip As New frmScheduleTrip
Me.AddOwnedForm(ScheduleTrip)
ScheduleTrip.Show()
In frmScheduleTrip I am trying to refresh UI elements on the main form.
Code:
Me.GetType.InvokeMember("RefreshUI", Reflection.BindingFlags.InvokeMethod, Me.Owner.GetType.DefaultBinder, Me.Owner.Handle, New Object)
But I get System.InvalidCastException
I'm obviously doing something wrong, any ideas?
Re: Trying to call a method in one form from a different form
Whay aren't you just casting the Owner property to the appropriate type and calling the method directly?
VB Code:
DirectCast(Me.Owner, MainForm).RefreshUI()
Is there some issue like the child form may be owned by various forms of different types, or that you are trying to cross a thread boundary?
Re: Trying to call a method in one form from a different form
Why? Well, because I'm a n00b. lol. I still don't know all the in's and out's of .NET.
Thanks for pointing that out to me. It works.
Re: Trying to call a method in one form from a different form [resolved]
Sorry. With the number of posts you have I assumed a greater level of experience. I thought that there must be a specific reason you were trying such an indirect method, but unfamiliarity is as good a reason as any. :)