But wouldn't code execution stop on ShowDialog if it was modal?
Main Topics
Browse All TopicsI have the following code:
Dim dlg2 As New dlgDBSelect
dlg2.DatabaseArrayList = arlDBList
dlg2.ShowDialog()
When the code gets to "dlg2.ShowDialog()", I can see the dialog form flash on the screen, but it does not stay modal.
What gives?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You are correct, .ShowDialog() should open the form as modal.
Do you have anything on dlgDBSelect that could be closing it?
If not, i would suggest putting a breakpoint on the line when you ShowDialog() and stepping through the code.
If dlgDBSelect is part of the main project you could also use my.forms.dlgDBSelect.ShowD
There is no code in dlgDBSelect that would close the form. In fact, if I comment out all the code within the form, the problem remains.
I did try single-stepping through the code. It goes into the form's load event where it loads a dropdown box on the form. Then, when it exits the form's load event, the code returns to the calling function as if it were a non-modal form.
During code execution, there are no errors thrown.
SteveR3110,
I tried adding the DoEvents as you suggest. It does nopt work, but now I get an error when the code leaves the procedure that contains the dialog code. The code does not stop anywhere (not even through sigle step, it throws the error right after "End Sub")
Attached is the error report given by VB.Net
Ok, here is the setup as it currently stands (I didn't write it, I'm adding some modifications).
The start up form is a "splash" form. It's Form_Load event calls a sub procedure called "DoProc()"
DoProc() causes a login form (user name and passord) to be displayed modally. This is old code and currently works.
There is a bit of code verifying the user then the Database selection form is to be displayed modally. (This is where I have the problem)
Once the database is selected, the splash screen is unloaded and the main form is displayed. This has been removed for the time being, until I can get the database selection form to work. As it currently sits, after the database selection form closes, the code exits DoProc() and then exits the splash screen's form load event which in turn exits the program.
What version VB.Net Clif?
By DEFAULT, when the "Startup Form" (the splash form in your case) closes the WHOLE app closes. In VB.Net 2005 (or above) this can be fixed with a simple Project --> Properties change.
Click on Project --> Properties and change the "Shutdown mode" from "When startup form closes" to "When last form closes".
In VB.Net 2005, you could also use the Application.Startup() Event to execute the login verification code. From there you can cancel the application if login fails and the main form will never be shown.
http://msdn.microsoft.com/
For earlier versions of VB.Net we would need to do some more "magic" to make it work...
You can still use a "Sub Main" in VB.Net 2005 (though I don't recommend it for most situations).
To use a Sub Main in VB.Net 2005 you have to UNCHECK the "Enable Application Framework" CheckBox in Project --> Properties. Then you will be able to select Sub Main as the Startup from the DropDown.
But then you are missing all the NEW functionality of the "Application Model":
http://msdn.microsoft.com/
Many people don't even realize the powerful new features that are available to them because they are "hidden" via a button in Project --> Properties. =\
Fairly simple, actually:
1. Startup Event
2. Splash Screen is displayed
3. dlgLogin is displayed. User types in name and password then clicks "Ok" which closes the form.
4. Once user enters name and password, an ArrayList of databases available to that user is created
5. dlgDBSelect is loaded
6. The ArrayList is passed to dlgDBSelect, which loads a drop-down combo.
Up to this point, everything works fine. The probnlem is that the dlgDBSelect does not stay Modal.
7. User selects DB and clicks "Ok", which closes the form.
8. Main form loads and is displayed until app is exited by the user.
I have a feeling the splash screen may be getting in the way...
Can you test with this?
1. Startup Event (ALL code below thru #6 is occurring HERE in this Event)
2. dlgLogin is displayed. User types in name and password then clicks "Ok" which closes the form.
3. Once user enters name and password, an ArrayList of databases available to that user is created
4. dlgDBSelect is loaded
5. The ArrayList is passed to dlgDBSelect, which loads a drop-down combo.
Up to this point, everything works fine. The probnlem is that the dlgDBSelect does not stay Modal.
6. User selects DB and clicks "Ok", which closes the form.
7. Main form loads and is displayed until app is exited by the user.
*** The Main form is set as the "Startup Object" in Project --> Properties. It loads ONLY because we have not cancelled the application in the Startup() Event with "e.Cancel = True".
Certainly. I trimmed out all the propietary code, and then ran it to make sure it still failed.
There is one thing that I hadn't noticed until now. (Lord knows why I didn't see it before). When the dlgDBSlect form flashes, the splash screen disappears. I have no code to close it in either the splash screen itself or during the load of dlgDBSelect. In fact I have commented out all the code in dlgDBSelect.
Ok, well, that worked. There is a window displayed with the title bar reading "Can you hear me now?" Aftre cling the "X" box to close, the application continues on to the main form.
It doesn't solve my problem, but it worked. I meen a login *and* the database select screens to display (in that order) before the main screen shows. I cannot combine the two because I need to populate the database list based on the username/password.
Just out of curiosity, does the "highly trimmed" code that you gave (and failed) work for you?
Well...this works for me:
Private Sub MyApplication_Startup(ByVa
Dim F1 As New Form
F1.Text = "Can you hear me now?"
F1.ShowDialog()
Dim F2 As New Form
F2.Text = "I'm still here..."
F2.ShowDialog()
End Sub
I get TWO different dialogs that display (and wait for me to close them) before I get to the Main Form of my test app.
So we have narrowed it down a bit...let's figure out which is causing the problem.
Can you get JUST the dlgDBSelect dialog to display by itself?
Business Accounts
Answer for Membership
by: angelIIIPosted on 2008-09-23 at 13:30:40ID: 22553721
I assume that code is in a sub or so?
that means that your variable dlg2 goes out of scope immediately, hence the form closes immediately.
you will have to declare the dlg2 on form level, so it won't go out of scope.