Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form2 Closes - how to notify form1 event

Status
Not open for further replies.

geedubcpa

Programmer
Oct 5, 2005
19
0
0
US
I have two forms in question.

Form1 is a transaction database
Form2 is a customer database

When you are on form1 there is a combobox that is populated with customer names. If your customer name is not present, you click on a button to open form2 which has the customer data.

When form2 is saved and you close, I want to have the combobox on form1 updated. The code to update the combobox is simple, but i need to place it in an event on form1 (right now the code is in the click event of a button) but I want to have the code fire automatically when form2 closes.

Where could i place the code to have the combobox update upon the close of form2

Thanks in advance for any help.




 
You could try something like:

Code:
  Private WithEvents Form2 As SecondForm

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    Form2 = New SecondForm
    Form2.Show()

  End Sub

  Private Sub Form2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Form2.Closed

    MessageBox.Show("SecondForm has closed")

  End Sub

Hope this helps

[vampire][bat]
 
Thanks for the response - I will try. I was able to come up to a solution on my own by doing research. Here is what i found and am using.


Just show Form2 using ShowDialog() instead of Show():

Private Sub Button1_Click(...) Handles Button1.Click
Dim f2 As New Form2
f2.ShowDialog() ' <--------- code stops here until f2 is closed
' do something else...
Button2_Click(Nothing, Nothing) ' make Button2s code run (or do something else here)
End Sub
 
You got the right idea geedubcpa.

Try something like this:

Code:
If f2.ShowDialog(Me) <> DialogResult.OK Then Exit Sub
'Do addition to combobox

Then in form 2 close it via the following methods:
Code:
Me.DialogResult = DialogResult.OK
'or
Me.DialogResult = DialogResult.Cancel

Your ComboBox addition would then only happen if the dialog returned OK.
 
ANd what happend to MVC??

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
MVC...

While I try to implement MVC - I sometimes find it difficult to do so. I self taught using VB5&6, and previously QBasic - so when I got to college and they tried to teach it, I had a hard time grasping it (though that might have something to do with the quality of the classes though too).

Maybe chrissie1, you could point out a good MVC example for us (I found that the easiest way to learn).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top