FolderBrowserDialog closes my dialog window
-
Hi everyone I have this strange thing happening, and can't seem to get past it. My application opens a new project dialog window where the user types in the name of the project, a description of the project, and has to open a FolderBrowserDialog to select the location of some files that the application will use. When I select the folder and click OK (or Cancel), it closes the FolderBrowserDialog as expected, but it also closes my new project dialog with a dialog result of Cancel. The new project dialog does not have the AcceptButton or CancelButton set. It uses Yes and No dialog results back to the main form. Anyone got any ideas? Thanks in advance. Paul
One day I want to be a code monkey. Right now, I'm more like a code amoeba...
-
Hi everyone I have this strange thing happening, and can't seem to get past it. My application opens a new project dialog window where the user types in the name of the project, a description of the project, and has to open a FolderBrowserDialog to select the location of some files that the application will use. When I select the folder and click OK (or Cancel), it closes the FolderBrowserDialog as expected, but it also closes my new project dialog with a dialog result of Cancel. The new project dialog does not have the AcceptButton or CancelButton set. It uses Yes and No dialog results back to the main form. Anyone got any ideas? Thanks in advance. Paul
One day I want to be a code monkey. Right now, I'm more like a code amoeba...
I can't reproduce this. I took a forms project and added a new form called Form2. On Form2 I added a button, and to this button a Click event handler that does the following code (ripped from the MSDN docs):
FolderBrowserDialog folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); // Show the FolderBrowserDialog. DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == DialogResult.OK) { string folderName = folderBrowserDialog1.SelectedPath; }
On my project's original Form1, I added a button with a Click event handler to launch the Form2 modal like this:
Form2 subForm = new Form2(); subForm.ShowDialog(this);
Running this, closing the FolderBrowserDialog does not close Form2. What have you done differently?
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I can't reproduce this. I took a forms project and added a new form called Form2. On Form2 I added a button, and to this button a Click event handler that does the following code (ripped from the MSDN docs):
FolderBrowserDialog folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); // Show the FolderBrowserDialog. DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == DialogResult.OK) { string folderName = folderBrowserDialog1.SelectedPath; }
On my project's original Form1, I added a button with a Click event handler to launch the Form2 modal like this:
Form2 subForm = new Form2(); subForm.ShowDialog(this);
Running this, closing the FolderBrowserDialog does not close Form2. What have you done differently?
Mark Salsbery Microsoft MVP - Visual C++ :java:
Thanks for your reply Mark. That's pretty much how I do it too. After instantiating the form or browser dialog, I update a few properties, then use the ShowDialog() method. Could it be a bug? My development environment is Windows 7 RC1, Visual Studio SP1, latest patches etc.
One day I want to be a code monkey. Right now, I'm more like a code amoeba...
-
Thanks for your reply Mark. That's pretty much how I do it too. After instantiating the form or browser dialog, I update a few properties, then use the ShowDialog() method. Could it be a bug? My development environment is Windows 7 RC1, Visual Studio SP1, latest patches etc.
One day I want to be a code monkey. Right now, I'm more like a code amoeba...
Poolee wrote:
Could it be a bug?
I suppose it's possible but I have never heard about it....maybe someone else will reply that has experienced the same behavior. That sure would break a lot of apps :) Does the same thing happen if you do what I did - create a new form, add a button that launches the folder browser dialog, and open that new form modally (with ShowDialog)?? Are you opening your new project dialog modally as well?
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Poolee wrote:
Could it be a bug?
I suppose it's possible but I have never heard about it....maybe someone else will reply that has experienced the same behavior. That sure would break a lot of apps :) Does the same thing happen if you do what I did - create a new form, add a button that launches the folder browser dialog, and open that new form modally (with ShowDialog)?? Are you opening your new project dialog modally as well?
Mark Salsbery Microsoft MVP - Visual C++ :java:
Hi Mark Created a project as you described... worked properly. I will have to review my code... and Dialog properties... LOL Still very weird... I will post the results if I manage to discover the cause. Thanks for your help! Paul
One day I want to be a code monkey. Right now, I'm more like a code amoeba...
-
Poolee wrote:
Could it be a bug?
I suppose it's possible but I have never heard about it....maybe someone else will reply that has experienced the same behavior. That sure would break a lot of apps :) Does the same thing happen if you do what I did - create a new form, add a button that launches the folder browser dialog, and open that new form modally (with ShowDialog)?? Are you opening your new project dialog modally as well?
Mark Salsbery Microsoft MVP - Visual C++ :java:
Ok, here's where I slap myself, bang my head against a particularly strong wall, then put my head down a toilet... gurgling NOOOOB as it flushes! I had copied the button from the Cancel button on the form. I had retained the DialogResult property of Cancel. So yeah, clicking the button opened the FolderBrowserDialog of course, then as soon as it closed, the DialogResult caused the form to close. Thanks again for your help Mark! Cheers Paul
One day I want to be a code monkey. Right now, I'm more like a code amoeba...
-
Ok, here's where I slap myself, bang my head against a particularly strong wall, then put my head down a toilet... gurgling NOOOOB as it flushes! I had copied the button from the Cancel button on the form. I had retained the DialogResult property of Cancel. So yeah, clicking the button opened the FolderBrowserDialog of course, then as soon as it closed, the DialogResult caused the form to close. Thanks again for your help Mark! Cheers Paul
One day I want to be a code monkey. Right now, I'm more like a code amoeba...
Good one ;P
Mark Salsbery Microsoft MVP - Visual C++ :java: