Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. FolderBrowserDialog closes my dialog window

FolderBrowserDialog closes my dialog window

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Poolee
    wrote on last edited by
    #1

    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...

    M 1 Reply Last reply
    0
    • P Poolee

      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...

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      P 1 Reply Last reply
      0
      • M Mark Salsbery

        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:

        P Offline
        P Offline
        Poolee
        wrote on last edited by
        #3

        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...

        M 1 Reply Last reply
        0
        • P Poolee

          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...

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          P 2 Replies Last reply
          0
          • M Mark Salsbery

            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:

            P Offline
            P Offline
            Poolee
            wrote on last edited by
            #5

            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...

            1 Reply Last reply
            0
            • M Mark Salsbery

              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:

              P Offline
              P Offline
              Poolee
              wrote on last edited by
              #6

              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...

              M 1 Reply Last reply
              0
              • P Poolee

                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...

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                Good one ;P

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups