Odd ShowDialog problem

D

dgk

I'm showing a form using ShowDialog (VB2003 in Visual Studio), and a
button on that form pops up a FolderBrowserDialog. As soon as the FBD
is closed, either by selecting or by cancel, the form exits. Not the
behavior that I was hoping for. Did I mess something up or is this the
way that it works?
 
C

Chris

dgk said:
I'm showing a form using ShowDialog (VB2003 in Visual Studio), and a
button on that form pops up a FolderBrowserDialog. As soon as the FBD
is closed, either by selecting or by cancel, the form exits. Not the
behavior that I was hoping for. Did I mess something up or is this the
way that it works?

Can we see some simplified code that shows the problem?

chris
 
D

dgk

Can we see some simplified code that shows the problem?

chris


In the main form (during load if app settings aren't created yet):

Dim frmOptions As New frmOpts
Dim RCF As DialogResult = frmOptions.ShowDialog
If RCF = DialogResult.Cancel Then Environment.Exit(1)
frmOptions.Close()


In frmOptions I declare this:

Private FBD As New System.Windows.Forms.FolderBrowserDialog

and in a button click event do this:

Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnBrowse.Click

FBD.ShowNewFolderButton = True
Dim J As DialogResult = FBD.ShowDialog
End Sub

Click on the button, the Folder dialog pops up. Click either Ok or
Cancel and the folderbrowser exits, and so does the form. I can likely
stop it in OnClosing since that code is certainly firing, but I have
no idea why it is happening.
 
C

Cor Ligthert [MVP]

DGK,

How do you set that OK in your code.

Return dialogresult.OK as the button OK is clicked will probably fix the
job.

Be aware that there are some bugs in this by setting the button using the
designer to OK.
(I am not sure anymore what it was, so I never use this)

I hope this helps,

Cor
 
D

dgk

DGK,

How do you set that OK in your code.

Return dialogresult.OK as the button OK is clicked will probably fix the
job.

Be aware that there are some bugs in this by setting the button using the
designer to OK.
(I am not sure anymore what it was, so I never use this)

I hope this helps,

Cor

I'm not sure that I understand this. I do set dialogresult.OK in the
OK button on the form, which is where the settings are actually
updated, but the OK that is from the FolderBrowserDialog is part of
the sealed class and I can't do anything about it. Apparently
selecting either button on the FBD object is somehow satisifying the
need for a dialog result for the form. But if that was so, I wouldn't
be the first one writing about it. I've looked through two years of
messages and there are quite a few on ShowDialog but none mention
this.
 
O

Oenone

dgk said:
I'm showing a form using ShowDialog (VB2003 in Visual Studio), and a
button on that form pops up a FolderBrowserDialog. As soon as the FBD
is closed, either by selecting or by cancel, the form exits.

What is the DialogResult property of the button on your form set to? If it's
something other than None, this could result in the behaviour you described.
 
D

dgk

What is the DialogResult property of the button on your form set to? If it's
something other than None, this could result in the behaviour you described.

I hadn't set the DialogResult to anything yet. I just tried setting it
to None in Load and still got the same behavior. So I made a new
project with just the essentials, one form showing another with
ShowDialog(Me) and having a button on that form pop up the
FolderDialogBrowser. It worked fine. So something else is weird in my
project. Maybe a custom control that I'm also using on that form is
causing problems? I'll gut it and see what happens.
 
D

dgk

I hadn't set the DialogResult to anything yet. I just tried setting it
to None in Load and still got the same behavior. So I made a new
project with just the essentials, one form showing another with
ShowDialog(Me) and having a button on that form pop up the
FolderDialogBrowser. It worked fine. So something else is weird in my
project. Maybe a custom control that I'm also using on that form is
causing problems? I'll gut it and see what happens.


Ok, I have now added a new form and built the code back up until it is
a duplicate of the original problem form. It works fine. I have no
idea what is different but I'm on vacation today and I'M GOING TO THE
BEACH NOW. I just couldn't go until I had this fixed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top