views:

214

answers:

2

I have a form which is displayed through: ShowDialog(). The form doesn't have CancelButton specified.

When I open a BrowseDialog from the form and then close the BrowseDialog, the form is also closed. How can I prevent this from happening?

When the "browse"-button is clicked:

browseDialog.SelectedPath = projectLocation.Text;
browseDialog.ShowDialog();

if (browseDialog.SelectedPath != "")
{
      projectLocation.Text = browseDialog.SelectedPath;
}

When the "cancel"-button of the form is clicked:

Close();
+2  A: 

I would guess that the button you use to show the BrowseDialog has its DialogResult set to something other than None.

If this is not the case, please post some code.

liggett78
Oh lol, that was it. I didn't even think of the Browse-button being set to Cancel. Thanks a lot! :D
MysticEarth
Yeah, can happen if you copy-paste controls.
liggett78
A: 

in your onclosing event from your browser dialog, do a check on the sender arg to see which dialog is requesting the close and if it's not the browser dlg, set e.Cancel = true

Tony