FolderBrowserDialog doesn't initialize

I

ImageAnalyst

I'm trying to have the user browse to a folder, once they click a
button, using the standard FolderBrowserDialog tool,
System.Windows.Forms.FolderBrowserDialog. I'm using VB.Net 2005.
There is a property, SelectedPath, that you're supposed to be able to
set that will initialize the folder browser window so that the tree
structure is already opened at that folder. The problem is that it
doesn't seem to work. No matter what I put, it has all the folders
and drives collapsed. It doesn't start off with the one I want open.
Anyone else experience this?

The help says:
"If the SelectedPath property is set before showing the dialog box,
the folder with this path will be the selected folder, as long as
SelectedPath is set to an absolute path that is a subfolder of
RootFolder (or more accurately, points to a subfolder of the shell
namespace represented by RootFolder)."

I want them to be able to pick any folder on their computer, and not
be limited to just those folders in a certain folder, like My
Documents, so I set RootFolder = Environment.SpecialFolder.MyComputer.
Regards,
ImageAnalyst


' Root folder has to be one of the special folders.
Me.FolderBrowserDialog1.RootFolder =
Environment.SpecialFolder.MyComputer

' Determine which folder they're about to start browsing
from.
' Doesn't work!
FolderBrowserDialog1.SelectedPath = "C:\Program Files"
' Show the FolderBrowserDialog opened at above folder
(doesn't work).
Dim result As DialogResult =
FolderBrowserDialog1.ShowDialog()
 
I

ImageAnalyst

Well maybe it is sort of picking it - I just couldn't see it because
of the low contrast on my notebook computer. But it only highlights
the folder and doesn't have it expanded to show all the subfolders.
Anyone know how to get it to expand the selected path? Like in my
example below, have Program Files folder be selected and expanded so
that all the subfolders of Program Files are shown and the user
doesn't have to double click to get it to expand. (I'd just like to
save them a step if possible).
Regards,
ImageAnalyst
 
S

ShaneO

ImageAnalyst said:
I'm trying to have the user browse to a folder, once they click a
button, using the standard FolderBrowserDialog tool,

You must understand that "SelectedPath" means just that - Selected. It
doesn't mean - OpenThePath or ExpandThePath.

The quickest way I could think of to achieve your required result is as
follows (watch for wrapping) -

With FolderBrowserDialog1
Dim sString() As String =
System.IO.Directory.GetDirectories("C:\Program Files", "*.",
SearchOption.TopDirectoryOnly)
.SelectedPath = sString(0)
Dim result As DialogResult = .ShowDialog
End With

Obviously you'd need to add Error Handling etc., but this should get you
started. Hopefully someone else will know of a better way.


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
I

ImageAnalyst

ShaneO:
Sorry for the late thanks. I did use your workaround (regarding
opening a subfolder) and it works fine.
Thanks,
ImageAnalyst
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top