Results 1 to 4 of 4

Thread: Trying to call a method in one form from a different form [resolved]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. 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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width