By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,516 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Apr 4 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.

Apr 4 '06 #2

P: n/a
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?

Apr 4 '06 #3

P: n/a
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
"Aziz" wrote:
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?

Apr 4 '06 #4

P: n/a
VJ
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

"Aziz" <az*****@googlemail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
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?

Apr 4 '06 #5

P: n/a
jvb
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.

Apr 4 '06 #6

P: n/a
Thanks everyone. Code worked great.

Apr 5 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.