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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open File Dialog - Display Multiple Times?

Status
Not open for further replies.

jasonp45

Programmer
Aug 23, 2001
212
US
When my app starts the OpenFileDialog is displayed, and the user selects a file.

After the filename is captured, my code tells the OpenFileDialog to display again so the user will select a second file, at which time I capture the second filename.

However, when the OpenFileDialog is invoked the second time, it does not display. If I press Alt->Tab (in Windows Vista or XP) the dialog shows up, so it is working in a sense, but it isn't showing up on my screen unless I Alt->Tab.

How can I get the dialog to show up the second time automatically after the dialog disappears the first time?

I have tried creating a new dialog, adding a second form with its own dialog, along with various form and dialog refresh, dispose, show commands - nothing seems to work. I've posted the latest iteration of my code below. Thanks for any help!

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cd1 As New System.Windows.Forms.OpenFileDialog
With cd1
.Title = "Select 'D' File"
.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
.Filter = "*_D*.txt|*_D*.txt"
.ShowDialog()
sFileName1 = .FileName
End With
With cd1
.Title = "Select 'PI' File"
.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
.Filter = "*_PI*.txt|*_PI*.txt"
.ShowDialog()
sFileName2 = .FileName
End With
End Sub
 
I just ran you code in vs2005 and it works just fine. Both dialogs show up on top.

For some reason, your/a form is taking the focus from your dialog. Is the other form in an "Always on Top" state?

Senior Software Developer
 
No. I just added a 'Me.SendToBack' command between the two dialogs and the result is the same. It is very strange, but at least I know I'm not crazy - it *should* work.

PS - I'm running VS2005 Team Edition for Software Developers, version 8.0.5....
 
hmmm... this is strange.

After the Dialog gets the focus via your Alt-Tab, does it allow you to put the focus back onto the parent form, or does it beep and maintain the focus like it should?

I'm Taking a stab in the dark here, but you could also try using cd1.Reset in between the two.

Senior Software Developer
 
Yes, when I alt-tab the second dialog keeps the focus.

I've already tried the cd1.Reset...no luck.

Thanks for your help; I just worked around it by using a VBScript common dialog to load the filenames I need, then shell out to the .Net program and pass the filenames as parameters. Ugly, but it will work for now.
 
Use ShowDialog(IWin32Window Owner)

i.e. cd1.ShowDialog(this);

This will make your main force the parent of the dialog window and will therefore push the parent form behind the dialog.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top