Multiple child forms - updating the right one

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

    #1

    Multiple child forms - updating the right one

    I've got an mdiParent form. I open an instance of a child form like
    this:

    Dim frmChild as New frmCustomers
    frmChild.Show()

    I've got a few of these open at a time. On each frmChild I open
    another form that displays customer data. When I make changes and save
    the customer data, I need the updated data to show on the correct
    frmChild. How do I know which form opened the customer data form and
    how would I reference it?
  • tomb

    #2
    Re: Multiple child forms - updating the right one

    You could use a controlling class that opens all the child forms,
    specifying the mdi form as its mdiform. The controlling class can keep
    track of which form has the request to open the data form, and the
    controlling class can manage that also. So when the update needs to be
    done, the controlling class then handles the placement of the data into
    the correct form.

    Tom

    Kevin wrote:
    >I've got an mdiParent form. I open an instance of a child form like
    >this:
    >
    >Dim frmChild as New frmCustomers
    >frmChild.Show( )
    >
    >I've got a few of these open at a time. On each frmChild I open
    >another form that displays customer data. When I make changes and save
    >the customer data, I need the updated data to show on the correct
    >frmChild. How do I know which form opened the customer data form and
    >how would I reference it?
    >
    >

    Comment

    • Kevin

      #3
      Re: Multiple child forms - updating the right one

      Could you give me a "for instance"?


      On Wed, 27 Sep 2006 17:30:20 -0400, tomb <tomb@technetce nter.com>
      wrote:
      >You could use a controlling class that opens all the child forms,
      >specifying the mdi form as its mdiform. The controlling class can keep
      >track of which form has the request to open the data form, and the
      >controlling class can manage that also. So when the update needs to be
      >done, the controlling class then handles the placement of the data into
      >the correct form.
      >
      >Tom
      >
      >Kevin wrote:
      >
      >>I've got an mdiParent form. I open an instance of a child form like
      >>this:
      >>
      >>Dim frmChild as New frmCustomers
      >>frmChild.Show ()
      >>
      >>I've got a few of these open at a time. On each frmChild I open
      >>another form that displays customer data. When I make changes and save
      >>the customer data, I need the updated data to show on the correct
      >>frmChild. How do I know which form opened the customer data form and
      >>how would I reference it?
      >>
      >>

      Comment

      • GhostInAK

        #4
        Re: Multiple child forms - updating the right one

        Hello Kevin,

        -CALLER-
        tFormVariable.S how(me)

        -DATA FORM-
        if not nothing is me.owner then
        ' We got a live one.
        endif

        -Boo

        I've got an mdiParent form. I open an instance of a child form like
        this:
        >
        Dim frmChild as New frmCustomers
        frmChild.Show()
        I've got a few of these open at a time. On each frmChild I open
        another form that displays customer data. When I make changes and save
        the customer data, I need the updated data to show on the correct
        frmChild. How do I know which form opened the customer data form and
        how would I reference it?
        >

        Comment

        • Kevin

          #5
          Re: Multiple child forms - updating the right one

          Thanks, but the .Show(Me) function won't work with MDI Child forms,
          which my form needs to be.


          On Thu, 28 Sep 2006 00:43:22 +0000 (UTC), GhostInAK
          <ghostinak@gmai l.comwrote:
          >Hello Kevin,
          >
          >-CALLER-
          >tFormVariable. Show(me)
          >
          >-DATA FORM-
          >if not nothing is me.owner then
          >' We got a live one.
          >endif
          >
          >-Boo
          >
          >
          >I've got an mdiParent form. I open an instance of a child form like
          >this:
          >>
          >Dim frmChild as New frmCustomers
          >frmChild.Show( )
          >I've got a few of these open at a time. On each frmChild I open
          >another form that displays customer data. When I make changes and save
          >the customer data, I need the updated data to show on the correct
          >frmChild. How do I know which form opened the customer data form and
          >how would I reference it?
          >>
          >

          Comment

          • Sca_Tone

            #6
            Re: Multiple child forms - updating the right one

            Hi Kevin,
            You would add code that works in the same way the MDIParent calls
            the ChildForm.

            eg.
            Dim frmChild as New frmCustomers
            frmChild.MdiPar ent = Me
            frmChild.Show()
            >From the code above you now have an MDIParent with a linked Child as
            you orginally stated.
            Then you state you call another form from the child to amend customer
            data.

            eg.
            Dim frmNewForm as new frmCustomerData
            frmNewForm.Show ()

            **** THE FIX ****
            In the customer data form you load from the child, you need to add a
            '/ ADD TO CUSTOMER DATA FORM
            Private _ParentForm As Form
            Public Property ParentForm() As Form
            Get
            Return _ParentForm
            End Get
            Set(ByVal value As Form)
            _ParentForm = value
            End Set
            End Property

            Then you call the customer data form as below
            Dim frmNewForm as new frmCustomerData
            frmNewForm.Pare ntForm = frmChild
            frmNewForm.Show ()

            This allows you from the customer data form to alter the field values
            on the child form
            _ParentForm.Tex tBox1.Text = "Joe Bloggs"

            Regards,
            Tony


            Kevin wrote:
            I've got an mdiParent form. I open an instance of a child form like
            this:
            >
            Dim frmChild as New frmCustomers
            frmChild.Show()
            >
            I've got a few of these open at a time. On each frmChild I open
            another form that displays customer data. When I make changes and save
            the customer data, I need the updated data to show on the correct
            frmChild. How do I know which form opened the customer data form and
            how would I reference it?

            Comment

            • Kevin

              #7
              Re: Multiple child forms - updating the right one

              When I've tried these suggestions, other forms weren't able to access
              my 'CustomerData' form. So here's what I came up with in case anybody
              cares or wants to do the same thing:

              'Find the correct frmCustomers that opened this form and update the
              grid
              For X = 0 To (frmMain.MdiChi ldren.Length) - 1
              Dim tempChild As Form = CType(frmMain.M diChildren(X),
              Form)
              If tempChild.Name = "frmCustome rs" Then
              Dim CallingForm As frmCustomers =
              DirectCast(temp Child, frmCustomers)
              If CallingForm.txt CourseID.Text = Me.txtCourseID. Text
              Then
              CallingForm.Loa dChkbox()

              'Locate the updated record in the Grid1
              For Y = 0 To CallingForm.Gri d1.Rows.Count - 1
              If CallingForm.Gri d1.Rows(Y).Cell s(0).Value =
              txtCustomerNumb er.Text Then
              CallingForm.Gri d1.CurrentCell =
              CallingForm.Gri d1.Rows(Y).Cell s(1)
              Exit For
              End If
              Next Y
              Me.Close()
              CallingForm.Sho w()
              CallingForm.Gri d1.Focus()
              Exit For
              End If
              End If
              Next X

              When I open the CustomerData form, I fill a textbox with the customer
              number on both forms. I then look for that customer number in the
              textbox on all frmCustomers. It works.



              On 28 Sep 2006 15:05:58 -0700, "Sca_Tone" <swiftanthony@h otmail.com>
              wrote:
              >Hi Kevin,
              You would add code that works in the same way the MDIParent calls
              >the ChildForm.
              >
              >eg.
              >Dim frmChild as New frmCustomers
              >frmChild.MdiPa rent = Me
              >frmChild.Show( )
              >
              >>From the code above you now have an MDIParent with a linked Child as
              >you orginally stated.
              >Then you state you call another form from the child to amend customer
              >data.
              >
              >eg.
              >Dim frmNewForm as new frmCustomerData
              >frmNewForm.Sho w()
              >
              >**** THE FIX ****
              >In the customer data form you load from the child, you need to add a
              '/ ADD TO CUSTOMER DATA FORM
              Private _ParentForm As Form
              Public Property ParentForm() As Form
              Get
              Return _ParentForm
              End Get
              Set(ByVal value As Form)
              _ParentForm = value
              End Set
              End Property
              >
              >Then you call the customer data form as below
              Dim frmNewForm as new frmCustomerData
              frmNewForm.Pare ntForm = frmChild
              frmNewForm.Show ()
              >
              >This allows you from the customer data form to alter the field values
              >on the child form
              _ParentForm.Tex tBox1.Text = "Joe Bloggs"
              >
              >Regards,
              Tony
              >
              >
              >Kevin wrote:
              >I've got an mdiParent form. I open an instance of a child form like
              >this:
              >>
              >Dim frmChild as New frmCustomers
              >frmChild.Show( )
              >>
              >I've got a few of these open at a time. On each frmChild I open
              >another form that displays customer data. When I make changes and save
              >the customer data, I need the updated data to show on the correct
              >frmChild. How do I know which form opened the customer data form and
              >how would I reference it?

              Comment

              Working...