Passing data between forms?

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

    #1

    Passing data between forms?

    How would I send information from DataGrid on the main form of the
    application to a modal popup form and then pass any changes to the data back
    to the main form and database when the popup form was closed?

    Thanks
  • Tor BÃ¥dshaug

    #2
    RE: Passing data between forms?

    Assuming that you know how to read the data in question from the datagrid and
    update it, you can:

    1)from the event handler that you want to use to fire the modal popup form,
    ensure that the required data is passed:

    Private Sub MainForm_Double Click(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles MyBase.DoubleCl ick
    Dim Other As ModalPopupForm

    Other = New ModalPopupForm
    Other.DataToBeE dited = dataToBeEdited '
    Other.Show()
    End Sub

    2)In the desired event in the modal popup, ensure that updated data is
    propagated back into the datagrid. Since it is a modal popup, I suggest

    Private Sub ModalPopupForm_ Closing(ByVal sender As Object, ByVal e As
    System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
    Dim closingForm As ModalPopupForm
    closingForm = CType(sender, ModalPopupForm)
    updateDataGrid( closingForm.Edi tedData)
    End Sub

    To finish this, you must implement the ModalPopupForm' s DataToBeEdited and
    EditedData properties, as well as the updateDataGrid-method.
    Alternatively, you can pass the datagrid itself as the
    'DataToBeEdited '-property. In this case you can drop implementing
    updateDataGrid at all, but this latter approach creates an extremely tight
    coupling between MainForm and ModalPopupForm which is generally not desirable.

    Tor BÃ¥dshaug
    tor.badshaug(AT )bekk.no

    Comment

    • Cor Ligthert

      #3
      Re: Passing data between forms?

      Job,

      When you ask this kind of question in this newsgroup, tell than next time if
      you use C# or VBNet. Althoug a language newsgroup is in my opinion more
      proper. It can in VBNet be something as

      Dim frm as myPopupForm
      frm.datafromGri d = DataFromGrid
      frm.showdialog
      WhateverIWantfr omMyPopupForm = frm.WhateverIWa nt
      frm.dispose

      I hope this helps,

      Cor


      Comment

      • Job Lot

        #4
        Re: Passing data between forms?

        someone suggested me this which seems quite straight forward

        I would use the method of showing the add/edit window(s) as dialog forms
        from the main form. This will allow you to instantiate the add/edit window
        from the same form as your datagrid/datasource. You can then get the current
        row from the datasource and use it as the datasource for databinding to
        controls on the add/edit form. After the user is finished with the add/edit
        form and they click ok, you can call update on your dataadapter(s). This
        method makes it easy because you can do everything from a single routine. You
        don't really need to pass a lot of references between forms; just set and
        read the property values of the controls on the add/edit form.


        "Cor Ligthert" wrote:
        [color=blue]
        > Job,
        >
        > When you ask this kind of question in this newsgroup, tell than next time if
        > you use C# or VBNet. Althoug a language newsgroup is in my opinion more
        > proper. It can in VBNet be something as
        >
        > Dim frm as myPopupForm
        > frm.datafromGri d = DataFromGrid
        > frm.showdialog
        > WhateverIWantfr omMyPopupForm = frm.WhateverIWa nt
        > frm.dispose
        >
        > I hope this helps,
        >
        > Cor
        >
        >
        >[/color]

        Comment

        • Job Lot

          #5
          RE: Passing data between forms?

          someone suggested me this which seems quite straight forward

          I would use the method of showing the add/edit window(s) as dialog forms
          from the main form. This will allow you to instantiate the add/edit window
          from the same form as your datagrid/datasource. You can then get the current
          row from the datasource and use it as the datasource for databinding to
          controls on the add/edit form. After the user is finished with the add/edit
          form and they click ok, you can call update on your dataadapter(s). This
          method makes it easy because you can do everything from a single routine. You
          don't really need to pass a lot of references between forms; just set and
          read the property values of the controls on the add/edit form.


          "Tor BÃ¥dshaug" wrote:
          [color=blue]
          > Assuming that you know how to read the data in question from the datagrid and
          > update it, you can:
          >
          > 1)from the event handler that you want to use to fire the modal popup form,
          > ensure that the required data is passed:
          >
          > Private Sub MainForm_Double Click(ByVal sender As Object, ByVal e As
          > System.EventArg s) Handles MyBase.DoubleCl ick
          > Dim Other As ModalPopupForm
          >
          > Other = New ModalPopupForm
          > Other.DataToBeE dited = dataToBeEdited '
          > Other.Show()
          > End Sub
          >
          > 2)In the desired event in the modal popup, ensure that updated data is
          > propagated back into the datagrid. Since it is a modal popup, I suggest
          >
          > Private Sub ModalPopupForm_ Closing(ByVal sender As Object, ByVal e As
          > System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
          > Dim closingForm As ModalPopupForm
          > closingForm = CType(sender, ModalPopupForm)
          > updateDataGrid( closingForm.Edi tedData)
          > End Sub
          >
          > To finish this, you must implement the ModalPopupForm' s DataToBeEdited and
          > EditedData properties, as well as the updateDataGrid-method.
          > Alternatively, you can pass the datagrid itself as the
          > 'DataToBeEdited '-property. In this case you can drop implementing
          > updateDataGrid at all, but this latter approach creates an extremely tight
          > coupling between MainForm and ModalPopupForm which is generally not desirable.
          >
          > Tor BÃ¥dshaug
          > tor.badshaug(AT )bekk.no[/color]

          Comment

          Working...