Results 1 to 9 of 9

Thread: Ever used a commondialog anyone ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    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

  2. #2
    Guest
    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

  3. #3
    Member
    Join Date
    Jul 1999
    Location
    J-ville, NC
    Posts
    54

    Lightbulb

    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|"
    David Underwood
    Cannabatech Corporation

    ICQ - 14028049
    E-mail - [email protected]

    AIM - DK4ever23[/b]


  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    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...

  5. #5
    Member
    Join Date
    Jul 1999
    Location
    J-ville, NC
    Posts
    54
    Ummmmm....what command button?
    David Underwood
    Cannabatech Corporation

    ICQ - 14028049
    E-mail - [email protected]

    AIM - DK4ever23[/b]


  6. #6
    Guest
    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

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    the ok (open) button, it the component that controls
    the enabled or not feature...

  8. #8
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    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.

  9. #9
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width