472,975 Members | 1,105 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

FolderBrowserDialog doesn't initialize

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()

Mar 11 '07 #1
3 6659
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

On Mar 11, 3:09 pm, "ImageAnalyst" <imageanal...@mailinator.com>
wrote:
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()

Mar 11 '07 #2
ImageAnalyst wrote:
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.
Mar 11 '07 #3
ShaneO:
Sorry for the late thanks. I did use your workaround (regarding
opening a subfolder) and it works fine.
Thanks,
ImageAnalyst

On Mar 11, 7:07 pm, ShaneO <spc...@optusnet.com.auwrote:
ImageAnalystwrote:
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.

Apr 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Anja | last post by:
I have installed the new Visual Studio 2003 and implemented the FolderBrowserDialog. Everything works fine, if I open the FolderBrowserDialog before opening a Database Connection. If I open...
1
by: alf | last post by:
Hi, I am using a FolderBrowserDialog to allow the user to select a folder as follows: FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); folderBrowserDialog1.RootFolder =...
9
by: hhh12347 | last post by:
FolderBrowserDialog crashes on my Windows 2000 computer. Here is a C# test program: using System; using System.Windows.Forms; public class TestForm : Form { FolderBrowserDialog...
0
by: Alpha | last post by:
My FolderBrowserDialog shows just the description on the top then 3 buttons (OK, Cancel, NewFolder) at the buttom of the dialog. It doesn't desplay the directory tree. I even specified not to...
6
by: John Krueger | last post by:
The FolderBrowserDialog control in my toolbox has vanished! I did not delibratly remove it and it is just not there anymore. I tried to add it back to the toolbox but there isn't even a .NET...
5
by: Scott M. Lyon | last post by:
My application (a VB.NET 2003 WinApp) currently has first an OpenFileDialog (asking for an input file to the process I'm working on), and then once the user selects that, it brings up a...
4
by: hotmit | last post by:
I'm trying to create a program that dynamicly saves and loads path of a FolderBrowserDialog , but I ran into a problem. Since FolderBrowserDialog is not a Control, therefore it doesn't have...
3
by: antuantuan | last post by:
Hi. How can I initialize a FolderBrowserDialog choosing a particular RootFolder? I saw that FolderBrowserDialog has a RootFolder member, but it accepts only an Environment.SpecialFolder (but I...
2
by: Marcel Brekelmans | last post by:
Hi, I'm trying to display a MessageBox after a FolderBrowserDialog. I see that it gets displayed, but not activated. The form is not in front and when I have some other forms open the MessageBox...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.