How to detect when ShowDialog object has closed? (2003)

  • Thread starter Thread starter Aziz
  • Start date Start date
A

Aziz

Here's the problem.
On my OrderForm the user can click a link to open up the AddCustomer
form to add a new customer, when AddCustomer form closes, it saves the
customer to the DataBase. The AddCustomer form is currently opened as a
Modal form using ShowDialog.

At the moment to see the newly added customer (in a ComboBox)I have to
click a button to close, then re-open the OLEDbConnection, re-fill the
DataSet then call the ComboBox fill method again. How do I enable it so
these commands are done automaticaly when the AddCustomer form closes?
Bear in mind that the AddCustomer form can itself be also loaded from
the MainMenu.

I tried the OrderForm's Got_Focus event but that doesn't work.

Any ideas?
 
Aziz as i understand ur problem, use datasets for this purpose. When
the record is inserted successfully, return its result as dataset and
add the value in the combobox otherwise dont insert it.
 
My fault for not being more clear.

Basically what I want to know is if I Open Form2 from Form1 using
ShowDialog, how can Form1 know when Form2 has closed?
 
Aziz,

When you show the form with ShowDialog your code waits until the shown form
is closed and then continues with the next line of code after the ShowDialog.

So after the line of code that shows the form, have a line of code that
clicks the button that you are currently clicking manually.

Kerry Moorman
 
AddHandler Form2.Closed, Addressof frm_Closed
Form2.ShowDialog()

private sub frm_Closed(sender as object , e as EventArgs)

// Write code here to do things when Form2 is closed...

end sub
 
Use the DialogResult. In the sub that calls the instance of Form2, try
something like this...

Dim frm2 As New Form2

Select Case frm2.ShowDialog()
Case DialogResult.Ok
'Perform any actions
Case DialogResult.Cancel
'Do not update database
End Select

In your Form2 code, add Me.DialogResult = DialogResult.Ok to the "Ok"
(or add, whatever) button and Me.DialogResult = DialogResult.Cancel to
the Form2 "Cancel" (or abort, reject, etc.) button. You may also want
to add this to the close event if the ok button is not pressed, up to
you.
 
Back
Top