Communication between forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Selva Chinnasamy

    #1

    Communication between forms

    I have multiple Mdi Child forms.

    Form1 is displaying all the orders list,
    Form2 is displaying all the product list.

    When I rename a Product name on Form3, I wanted to update contents in Form1
    and 2.

    Right now the Function renaming the Product is calling
    reload functions in Form1 and 2, but its not refreshed.

    Thanks In advance for your help.





  • VJ

    #2
    Re: Communication between forms

    You may want to look into the concepts of delegates and events... Its more
    like when you click a button, you write code in response to the click, in
    the click event. So you will write a delegate/event in Form3 and subscribe
    that in Form1 and Form 2, to perform the update in the notification event.
    you have to implement this event for your product object... and since
    product object is sued in Form 1 and Form 2, you can subscribe to it in the
    Form and perform the action on the update event... Codeproject.com or any
    vbproject samples websites have simple samples that explain the concept....,
    if you google you will get them

    VJ

    "Selva Chinnasamy" <selvarajuchinn asamy@online.no spam> wrote in message
    news:OPR6b0HZGH A.4248@TK2MSFTN GP05.phx.gbl...[color=blue]
    >I have multiple Mdi Child forms.
    >
    > Form1 is displaying all the orders list,
    > Form2 is displaying all the product list.
    >
    > When I rename a Product name on Form3, I wanted to update contents in
    > Form1
    > and 2.
    >
    > Right now the Function renaming the Product is calling
    > reload functions in Form1 and 2, but its not refreshed.
    >
    > Thanks In advance for your help.
    >
    >
    >
    >
    >[/color]


    Comment

    • Linda Liu [MSFT]

      #3
      RE: Communication between forms

      Hi Selva,
      Thank you for posting. From your post, my understanding on this issue is:
      how to update contents in Form1 and Form2 when the Product name in Form3
      changed. If I'm off base, please feel free to let me know.

      You can define an event for the change of the product name and write a
      method to trigger the event when the product name changes in Form3. Then
      subscribe the event and define corresponding event handling methods in
      Form1 and Form2. Thus when the product name in Form3 changes, the event
      will be raised and the corresponding event handling methods in Form1 and
      Form2 will be called.
      The following is a sample.

      // event defined in Form3
      public delegate void ProductNameChan gedEventHandler (int productID);
      public event ProductNameChan gedEventHandler EvtProductNameC hanged;
      private void OnProductNameCh anged(int id)
      {
      if (EvtProductName Changed != null)
      {
      EvtProductNameC hanged(id);
      }
      }

      // add reference variable of a instance of Form3 ,subscribe the event and
      define the handling method
      public Form3 frm3 = null;
      public Form1()
      {
      InitializeCompo nent();
      frm3.EvtProduct NameChanged += new
      Form3.ProductNa meChangedEventH andler(frm3_Evt ProductNameChan ged);
      }
      void frm3_EvtProduct NameChanged(int productID)
      {
      // add your update process here
      }

      You should assign the instance of Form3 to the reference variable "frm3"
      of Form1 in the MDI Parent.

      Hope this is helpful to you.
      Please don't hesitate to tell me if you have any other concerns, or need
      anything else.


      Sincerely,
      Linda Liu
      Microsoft Online Community Support

      =============== =============== =============== =======
      When responding to posts,please "Reply to Group" via
      your newsreader so that others may learn and benefit
      from your issue.
      =============== =============== =============== =======

      Comment

      • Cerebrus

        #4
        Re: Communication between forms

        Hi Linda,

        Thanks for your post. It is helpful to me as well. I'm not that strong
        on delegates.

        But since this is a VB newsgroup, could you explain how the same thing
        would be done in VB.NET ? Would it be as simple as converting the code
        to VB.NET ?

        Thanks in advance,

        Regards,

        Cerebrus.

        Comment

        • Linda Liu [MSFT]

          #5
          Re: Communication between forms

          Hi Cerebrus,

          The following is a sample written in VB.NET.
          // event defined in Form3
          Public Event EvtProductNameC hanged(ByVal productID As Integer)
          Private Sub OnProductNameCh anged(ByVal id As Integer)
          RaiseEvent EvtProductNameC hanged(id)
          End Sub

          // add reference variable of a instance of Form3 , define the event
          handling method
          Public WithEvents frm3 As Form3
          Private Sub frm3_EvtProduct NameChanged(ByV al productID As Integer)
          Handles frm3.EvtProduct NameChanged
          ' add your update process here
          End Sub

          You should assign the instance of Form3 to the reference variable "frm3"
          of Form1 in the MDI Parent.
          Hope this is helpful to you.

          Sincerely,
          Linda Liu
          Microsoft Online Community Support

          =============== =============== =============== =======
          When responding to posts,please "Reply to Group" via
          your newsreader so that others may learn and benefit
          from your issue.
          =============== =============== =============== =======

          Comment

          • Cerebrus

            #6
            Re: Communication between forms

            Thank you Linda, much appreciated.

            Regards,

            Cerebrus.

            Comment

            • Linda Liu [MSFT]

              #7
              Re: Communication between forms

              Hi Cerebrus, you're welcome!


              Sincerely,
              Linda Liu
              Microsoft Online Community Support

              =============== =============== =============== =======
              When responding to posts,please "Reply to Group" via
              your newsreader so that others may learn and benefit
              from your issue.
              =============== =============== =============== =======

              Comment

              • Selva

                #8
                Re: Communication between forms

                Thanks A Bunch Linda.

                Selva

                "Linda Liu [MSFT]" wrote:
                [color=blue]
                > Hi Cerebrus,
                >
                > The following is a sample written in VB.NET.
                > // event defined in Form3
                > Public Event EvtProductNameC hanged(ByVal productID As Integer)
                > Private Sub OnProductNameCh anged(ByVal id As Integer)
                > RaiseEvent EvtProductNameC hanged(id)
                > End Sub
                >
                > // add reference variable of a instance of Form3 , define the event
                > handling method
                > Public WithEvents frm3 As Form3
                > Private Sub frm3_EvtProduct NameChanged(ByV al productID As Integer)
                > Handles frm3.EvtProduct NameChanged
                > ' add your update process here
                > End Sub
                >
                > You should assign the instance of Form3 to the reference variable "frm3"
                > of Form1 in the MDI Parent.
                > Hope this is helpful to you.
                >
                > Sincerely,
                > Linda Liu
                > Microsoft Online Community Support
                >
                > =============== =============== =============== =======
                > When responding to posts,please "Reply to Group" via
                > your newsreader so that others may learn and benefit
                > from your issue.
                > =============== =============== =============== =======
                >
                >[/color]

                Comment

                • Linda Liu [MSFT]

                  #9
                  Re: Communication between forms

                  Hi Selva,

                  You are welcome!
                  If you have any other questions or concerns, please don't hesitate to
                  contact us. It is always our pleasure to be of assistant.

                  Have a nice day!


                  Sincerely,
                  Linda Liu
                  Microsoft Online Community Support

                  =============== =============== =============== =======
                  When responding to posts,please "Reply to Group" via
                  your newsreader so that others may learn and benefit
                  from your issue.
                  =============== =============== =============== =======

                  Comment

                  Working...