2015-10-13 342 views
0

我的應用程序想爲客戶提供一系列選項集。每套包含60個選項,主題變體。這些集合存儲在一個文件夾中。 Set1 set2等。我想使用文件夾瀏覽器來選擇一組,但我不希望用戶看到整個驅動器。我想將根文件夾設置爲父集。我嘗試過使用RootFolder,但是我發現這是行不通的。我也嘗試使用fileopenDialog,但我無法選擇一個文件夾。有第三種選擇嗎?設置自定義FolderBrowserDialog.RootFolder

+0

使用'System.IO.Directory.GetFiles()'和'一個ListBox'? – dummy

+1

您可以通過讓用戶命名集合來隱藏用戶的所有實現細節。然後當他們選擇一個名字時 - 你的代碼爲它們加載相關的集合。不需要**他們**來記住「set01」的含義或者他們存儲的位置。 – Plutonix

回答

0

RootFolder排序作品當與SelectedPath

Using fbd As New FolderBrowserDialog 
     fbd.RootFolder = Environment.SpecialFolder.MyComputer 
     fbd.SelectedPath = "H:\temp\scans" 
     If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then 
      MsgBox(fbd.SelectedPath) 
     End If 
    End Using 

這至少顯示所需的文件夾相結合 - 所有其它路徑仍然可用,如果用戶向上滾動。


這是我發現使用標準的OpenFileDialog在網上搜索最接近:

Using obj As New OpenFileDialog 
     obj.Filter = "foldersOnly|*.none" 
     obj.CheckFileExists = False 
     obj.CheckPathExists = False 
     obj.InitialDirectory = "C:\temp" 
     obj.CustomPlaces.Add("H:\OIS") ' add custom location 
     obj.CustomPlaces.Add("H:\Permits") ' add custom location 
     obj.Title = "Select folder - click Open to return opened folder name" 
     obj.FileName = "OpenFldrPath" 
     If obj.ShowDialog = Windows.Forms.DialogResult.OK Then 
      MsgBox(IO.Directory.GetParent(obj.FileName).FullName) 
     End If 
    End Using 

編輯CustomPlaces.Add()爲您的環境 - 這些文件夾顯示在右上方的導航面板。

`obj.FileName =「OpenFldrPath」」是有問題 - 在什麼可以例如被用來限制一個短語失敗。

注意到關於開放兩次點擊返回文件路徑。