Passing data between forms?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.DoubleClick
Dim Other As ModalPopupForm

Other = New ModalPopupForm
Other.DataToBeEdited = 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.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim closingForm As ModalPopupForm
closingForm = CType(sender, ModalPopupForm)
updateDataGrid(closingForm.EditedData)
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
 
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.datafromGrid = DataFromGrid
frm.showdialog
WhateverIWantfromMyPopupForm = frm.WhateverIWant
frm.dispose

I hope this helps,

Cor
 
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.
 
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.
 
Back
Top