-
Hi all,
I'am using a commondialog to display the DIR on a hard drive in one of my apps. I do this with the showopen property but the problem is that I don't want the user to select FILES, only DIRs.
I DON'T WANT THE COMMONDIALOG TO SHOW FILES, JUST DIRs.
I'am pretty sure there is a way to do so, (filter maybe),
any ideas ?
Thanks for your help
-
This is not the best way, but you can set the filter to some very unsual file extention so it wil not show any files. For example: rgsroigfs
-
Hmmmmmm........Well I don't think folders have certain file extensions, but you could just make up a file extension that doesn't exist....which would always show just the folders.
dlg1.Filter = "All Folders|*.abcdef|"
-
Thanks guys but whats with the command button,
it won't come enabled if I've specified a file extension
but haven't selected any files ???
We are close but, again a bit too far...
-
Ummmmm....what command button?
-
If you want to load it when you press a CommandButton, use this code.
Code:
Private Sub Command2_Click()
CommonDialog1.filename = ""
CommonDialog1.Filter = "|*.gufgfdgd" ' our weird extention
CommonDialog1.ShowOpen
End Sub
-
the ok (open) button, it the component that controls
the enabled or not feature...
-
I think Vince is talking about the Open button in the common dialog box. To get around this problem, use a ShowSave rather than a ShowOpen, and set the filename to something like 'Select a Location', then when the result comes back from the common dialog, filter out the filename and just use the path.
-
If you just want to browse for a folder, put this function in a module in your project.
Code:
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Const BIF_RETURNONLYFSDIRS = &H1
Private Declare Function SHGetPathFromIDList Lib "SHELL32.DLL" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "SHELL32.DLL" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long 'ITEMIDLIST
Public Function BrowseFolder(f As Form, szDialogTitle As String) As String
Dim x As Long, BI As BROWSEINFO, dwIList As Long, szPath As String, wPos As Integer
BI.hOwner = f.hwnd
BI.lpszTitle = szDialogTitle
BI.ulFlags = BIF_RETURNONLYFSDIRS
dwIList = SHBrowseForFolder(BI)
szPath = Space$(512)
x = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
If x Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
Else
BrowseFolder = ""
End If
End Function
and call it from your form with:
Code:
Return=BrowseFolder(Me,"Some title")
Then the variable Return will show what folder the user selected.