Button Click-> Directory search?

Jan 28, 2011 at 10:39pm
in visual Studio, how do I get a button click event to show a FolderBrowserDialog?
Jan 30, 2011 at 9:32pm
Bump
Feb 2, 2011 at 9:40pm
Last bump
Feb 2, 2011 at 10:21pm
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.
Feb 2, 2011 at 10:53pm
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.
Feb 2, 2011 at 11:23pm
so... is this C++/CLI then?

Show me some of your code. Like.. any function that does anything with a window.
Feb 3, 2011 at 8:51am
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 Feb 3, 2011 at 8:53am
Feb 3, 2011 at 9:14pm
2010 express C++
Feb 4, 2011 at 8:38am
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.
Feb 9, 2011 at 10:39pm
Thanks Grey Wolf. Sorry for the delayed "Thanks" I've been sick.
Feb 22, 2011 at 1:51am
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
Feb 22, 2011 at 8:49am
closed account (z05DSL3A)
thenewguy,

folderName could be a System::String^
Feb 22, 2011 at 9:36pm
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.