Problem Communicating Between Forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jasper Jones

    #1

    Problem Communicating Between Forms

    I have a main form which has a list of items from a table on my
    database. If I click one of these items it brings up a second form
    which lets you edit the details for that item. If I change an item's
    details and then close the edit form I want the main form to update its
    datagrid by calling the sub I wrote which refreshes the dataset.

    What is the best method of doing this; I know I can call commands after
    a showdialog form but I really don't want to use showdialog instead of
    show.

    Any help would be greatly appreciated. Please try and be specific as
    I'm still quite new to the Dot Net way of doing things.

  • Cor Ligthert [MVP]

    #2
    Re: Problem Communicating Between Forms

    Jasper,
    [color=blue]
    >
    > What is the best method of doing this; I know I can call commands after
    > a showdialog form but I really don't want to use showdialog instead of
    > show.
    >[/color]
    Why because if you use another from than you will have to do a lot with all
    those extra forms that a user is opening meanwhile on the first form. You
    have to prevent that your first form can be accessed. Showdialog does this
    direct for you.

    Cor


    Comment

    • CMM

      #3
      Re: Problem Communicating Between Forms

      Simple Solution:

      Have the first form subscribe to the second form's Closing event... like
      this:

      Dim frm as New Form2
      AddHandler(frm. Closing, AddressOf MyForm2ClosingP roc)
      frm.Show

      You can also create a new custom event in the second form that could
      communicate additional info to the first form.

      Better Solution
      Create a global Notifier class that forms can subscribe to and "hear"
      chatter from other forms. When the second form is closing it can do
      something like: GlobalNotifier. SendNotificatio n(Me,"Hey I'm Closing AND I
      updated some data")

      This is soooo simple to do.

      'declare this in a global module
      Public GlobalNotifier As New Notifier

      'notifier class
      Public Class Notifier

      Public Event Notify(sender As Object, e As NotifyEventArgs )

      Public Sub SendNotificatio ns(sender As Object, message as String)
      RaiseEvent Notify(sender, New NotifyEventArgs (message))
      End Sub

      End Class

      '... I think you can figure out the rest.



      "Jasper Jones" <jasperjoe@gmai l.com> wrote in message
      news:1139097125 .941950.249540@ f14g2000cwb.goo glegroups.com.. .[color=blue]
      >I have a main form which has a list of items from a table on my
      > database. If I click one of these items it brings up a second form
      > which lets you edit the details for that item. If I change an item's
      > details and then close the edit form I want the main form to update its
      > datagrid by calling the sub I wrote which refreshes the dataset.
      >
      > What is the best method of doing this; I know I can call commands after
      > a showdialog form but I really don't want to use showdialog instead of
      > show.
      >
      > Any help would be greatly appreciated. Please try and be specific as
      > I'm still quite new to the Dot Net way of doing things.
      >[/color]


      Comment

      Working...