Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make a FolderBrowserDialog's default path show up in a library instead of the actual disk?

Tags:

I know that if I set SelectedPath before I show the dialog I can get it to have a folder open by default when the dialog opens. However, the folder I want to use is very far down the list alphabetically. I have that same folder as one of my Libraries in Windows and it shows up at the of the listing, is there any way to have it default to the library version of the folder instead of the hard drive version of the folder?

Another potential solution would be if it did still use the drive version but it automatically scrolled the window down to where it was selected. Is there any way to do either of these solutions?


How it currently shows up

enter image description here

How I would like it to show up

enter image description here

like image 942
Scott Chamberlain Avatar asked Dec 06 '11 17:12

Scott Chamberlain


2 Answers

Set your root folder and selected path as such and it will auto-scroll there for you on the dialog opening:

FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.RootFolder = Environment.SpecialFolder.MyComputer;
dlg.SelectedPath = @"E:\Vetcentric";
dlg.ShowDialog();

enter image description here

The problem you run into is that if you watch the property assignments after selecting a folder located in the libraries hierarchy, it will still assign it to the genereic path that you would get via going through my computer.

like image 173
KreepN Avatar answered Oct 16 '22 22:10

KreepN


Use a Reset() call. This will make it auto-scroll.

        string prevpath = folderBrowserDialog1.SelectedPath;
        folderBrowserDialog1.Reset();
        folderBrowserDialog1.SelectedPath = bc.myWorkingDir;
        folderBrowserDialog1.ShowNewFolderButton = true;

        DialogResult dr = folderBrowserDialog1.ShowDialog();
        if (dr == DialogResult.OK || dr == DialogResult.Yes)
        {
            bc.myWorkingDir = folderBrowserDialog1.SelectedPath;
        }
        folderBrowserDialog1.SelectedPath = prevpath;
like image 33
eyeching Avatar answered Oct 17 '22 00:10

eyeching