Home All Groups Group Topic Archive Search About

Beginner help with FolderBrowserDialog

Author
27 Dec 2006 8:51 PM
chrisknapp
I'm learning VB and am making an application where I need a user to be
able to choose which folder his files are located in.  The folder path
chosen will be stored as a string for later use in the application.  I
tried adding FolderBrowserDialog to my form but can't figure out how to
get it to work.  I'm just above the 'Hello World' level here.  Thanks.

Author
27 Dec 2006 8:59 PM
Herfried K. Wagner [MVP]
<chriskn***@gmail.com> schrieb:
> I'm learning VB and am making an application where I need a user to be
> able to choose which folder his files are located in.  The folder path
> chosen will be stored as a string for later use in the application.  I
> tried adding FolderBrowserDialog to my form but can't figure out how to
> get it to work.  I'm just above the 'Hello World' level here.

Place a FolderBrowserDialog component on your form and add the code below to
a button's 'Click' event handler:

\\\
If _
    Me.FolderBrowserDialog.ShowDialog() = _
    System.Windows.Forms.DialogResult.OK _
Then
    MsgBox(Me.FolderBrowserDialog.SelectedPath)
End If
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
27 Dec 2006 9:13 PM
chrisknapp
Show quote Hide quote
> Place a FolderBrowserDialog component on your form and add the code below to
> a button's 'Click' event handler:
>
> \\\
> If _
>     Me.FolderBrowserDialog.ShowDialog() = _
>     System.Windows.Forms.DialogResult.OK _
> Then
>     MsgBox(Me.FolderBrowserDialog.SelectedPath)
> End If
> ///
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>


Very fast and excellent reply!  Thank you very much.  You made it much
easier than all the solutions I was finding on websites.  It is working
beautifully now!

I added your code and replaced the MsgBox with -

            strTestPath = (Me.FolderBrowserDialog1.SelectedPath)
            txtTestPath.Text = (Me.FolderBrowserDialog1.SelectedPath)


Thanks again!

Chris
Author
28 Dec 2006 2:26 AM
Bruce W. Darby
Chris,

Don't mean to make Herfried blush, but he's got a lot of good answers. My
abilities at coding are probably about the same as yours and he and the
others have helped me to learn a lot of stuff in a very short period of
time. One of the things that they have been able to show me is how to
condense my code to make it more efficient and, if you don't mind me adding
my two cents..

>            strTestPath = (Me.FolderBrowserDialog1.SelectedPath)
>            txtTestPath.Text = (Me.FolderBrowserDialog1.SelectedPath)

If you are using a control to store a value on your form, that value can be
called from anywhere in the code for that form at any time, so your two
lines of code can actually be condensed down to one line...

            txtTestPath.Text = Me.FolderBrowserDialog1.SelectedPath

I found out that I really didn't need the parentheses either, thanks to...
blush... these fine folks.

HTH,

Bruce
Author
28 Dec 2006 5:51 AM
chrisknapp
Bruce W. Darby wrote:
Show quoteHide quote
> Chris,
>
> Don't mean to make Herfried blush, but he's got a lot of good answers. My
> abilities at coding are probably about the same as yours and he and the
> others have helped me to learn a lot of stuff in a very short period of
> time. One of the things that they have been able to show me is how to
> condense my code to make it more efficient and, if you don't mind me adding
> my two cents..
>
> >            strTestPath = (Me.FolderBrowserDialog1.SelectedPath)
> >            txtTestPath.Text = (Me.FolderBrowserDialog1.SelectedPath)
>
> If you are using a control to store a value on your form, that value can be
> called from anywhere in the code for that form at any time, so your two
> lines of code can actually be condensed down to one line...
>
>             txtTestPath.Text = Me.FolderBrowserDialog1.SelectedPath
>
> I found out that I really didn't need the parentheses either, thanks to...
> blush... these fine folks.
>
> HTH,
>
> Bruce


Thank you Bruce.  I've changed it in my code!

Chris
Author
28 Dec 2006 6:44 PM
Herfried K. Wagner [MVP]
<chriskn***@gmail.com> schrieb:
> I added your code and replaced the MsgBox with -
>
>            strTestPath = (Me.FolderBrowserDialog1.SelectedPath)
>            txtTestPath.Text = (Me.FolderBrowserDialog1.SelectedPath)

Just remove the brackets on the right side, they do not make sense here.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
28 Dec 2006 3:13 AM
Cor Ligthert [MVP]
Be aware that if you don't install the servicepack in version Net 1.1 you
can get very serious errors.

:-)

Cor

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
news:%23HgoZnfKHHA.420@TK2MSFTNGP06.phx.gbl...
> <chriskn***@gmail.com> schrieb:
>> I'm learning VB and am making an application where I need a user to be
>> able to choose which folder his files are located in.  The folder path
>> chosen will be stored as a string for later use in the application.  I
>> tried adding FolderBrowserDialog to my form but can't figure out how to
>> get it to work.  I'm just above the 'Hello World' level here.
>
> Place a FolderBrowserDialog component on your form and add the code below
> to a button's 'Click' event handler:
>
> \\\
> If _
>    Me.FolderBrowserDialog.ShowDialog() = _
>    System.Windows.Forms.DialogResult.OK _
> Then
>    MsgBox(Me.FolderBrowserDialog.SelectedPath)
> End If
> ///
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>