newbie: Basic input dialog?

  • Thread starter Thread starter deko
  • Start date Start date
D

deko

I have a WinForms app that needs to take user input on open - before the
FormMain is displayed.

On the Form Load event of FormMain, I test for existence of an Access
database:

if (!File.Exists(Application.StartupPath +
"\\myAccess.mdb"))

If the mdb is not there, I need to open an input dialog form (with some
additional options) for selecting a different mdb:

FormDialogDifferentDatabase frmDialog =
new FormDialogDifferentDatabase();
frmDialog.Show();

How do I suspend execution of the code in the FormMain while the user
selects a different database? FormMain requires access to the database, so
I don't want to initialize it until it has a database. Should I put this
code in the constructor of FormMain?

Also, how do I get the user input from FormDialogDifferentDatabase? Do I
use DialogResult? I looked for examples of this but still confused...

Thanks in advance.
 
Open a form using .ShowDialog or if you use a OpenFileDialog control, it
will suspend code.

if File.Exists(Application.StartupPath +"\\myAccess.mdb") Then
'do your stuf...
else
dim OpenFileDialog1 as OpenFileDialog
With OpenFileDialog1
.InitialDirectory = "C:\"
.Filter = "All Files|*.*|DataBase|*.mdb|"
.FilterIndex = 2
End With
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim FilePath As String
FilePath = OpenFileDialog1.FileName
else
'Opps, didn't find the database so bail out
End If
 
Back
Top