Button Click-> Directory search?

in visual Studio, how do I get a button click event to show a FolderBrowserDialog?
Bump
Last bump
What library are you using? WinAPI?

IIRC, it's suprisingly complicated to open the folder browsing dialog in WinAPI. It's like a 5 step process and you have to do all these weird allocations.

I honestly don't remember how to do it -- I only did it once like 5 years ago.

If you're using some other widget library like Qt or wx, etc... it's much easier.
Not certain if it answers the question, but I'm making a Windows Form Application.
I'm trying to get the user to pick a directory, and my program copy a file from that directory.
so... is this C++/CLI then?

Show me some of your code. Like.. any function that does anything with a window.
closed account (z05DSL3A)
Do you know how to setup the event handler?

If so code like this should work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void folderButtonItem_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
      FolderBrowserDialog^ folderBrowserDialog1;
      folderBrowserDialog1 = gcnew System::Windows::Forms::FolderBrowserDialog;

      // Show the FolderBrowserDialog.
      System::Windows::Forms::DialogResult result = folderBrowserDialog1->ShowDialog();
      if ( result == ::DialogResult::OK )
      {
         folderName = folderBrowserDialog1->SelectedPath;
         //
         //
      }
}


Edit
If you don't know how to set an event handler, What version of VS are you using?
Last edited on
2010 express C++
closed account (z05DSL3A)
In form designer, right click on the button and select properties.
Towards the top of the Properties pane you should see an icon that looks like a bolt of lightning, click that.
In the list below find 'Click' and double click in the empty cell on the right.
This should generate and wire up the event handler for you.
Thanks Grey Wolf. Sorry for the delayed "Thanks" I've been sick.
at first I did this:


1
2
3
4
5
6
7
8
9
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
			      FolderBrowserDialog^ folderBrowserDialog1;
      folderBrowserDialog1 = gcnew System::Windows::Forms::FolderBrowserDialog;

      System::Windows::Forms::DialogResult result = folderBrowserDialog1->ShowDialog();
     
	   textBox2->Text = folderBrowserDialog1->SelectedPath;


Because I needed the textBox to say where it was going... However I now don't really need this. So my question is what is folderName, from your post?

String, Char? I'm just unsure of what to declare "folderName" as.


Thanks
closed account (z05DSL3A)
thenewguy,

folderName could be a System::String^
Thanks, last question is if the statement should look like this:


1
2
3
4
5
6
7
8
9
10
11
12
13
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
			 {

                                         System::String^ folderName;


			      FolderBrowserDialog^ folderBrowserDialog1;
      folderBrowserDialog1 = gcnew System::Windows::Forms::FolderBrowserDialog;

      System::Windows::Forms::DialogResult result = folderBrowserDialog1->ShowDialog();
     
	   textBox2->Text = folderBrowserDialog1->SelectedPath;
                          }
Topic archived. No new replies allowed.