|
-
Dec 5th, 2005, 12:01 AM
#1
Thread Starter
Fanatic Member
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?
Last edited by nkad; Dec 5th, 2005 at 12:25 AM.
-
Dec 5th, 2005, 12:13 AM
#2
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?
-
Dec 5th, 2005, 12:24 AM
#3
Thread Starter
Fanatic Member
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.
-
Dec 5th, 2005, 12:33 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|