CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    275

    How to select a folder in common dialog control

    How to Select a folder in Common dialog control?
    I know we can do this with DisListBox but i want to do it with Common Dialog Control

  2. #2
    Join Date
    Apr 2002
    Posts
    388
    I dont think there is a possibility to do this with the Common Dialog control. (At least I didnt find a flag how to do it.)

    But you could try to build your own CDlg Control (or Form) that has the same look and feel as the Microsofts where you are able to do this feature. But as I understood you you dont really want to do it.

    Another possiblility is to try to find any control in the web that makes you do it. Just try a search!!!

    Good luck
    mfg Ungi

    Music, music and VB. VB is like music: You never know how it is interpreted.

  3. #3
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110
    As far as I know U can't But u can use Windows API to solve this poblem
    Here is the Code.


    Bas COde

    Code:
    'This module contains all the declarations to use the
    'Windows 95 Shell API to use the browse for folders
    'dialog box. To use the browse for folders dialog box,
    'please call the BrowseForFolders function using the
    'syntax: stringFolderPath=BrowseForFolders(Hwnd,TitleOfDialog)
    '
    'For contacting information, see other module
    
    Option Explicit
    
    Public Type BrowseInfo
         hwndOwner As Long
         pIDLRoot As Long
         pszDisplayName As Long
         lpszTitle As Long
         ulFlags As Long
         lpfnCallback As Long
         lParam As Long
         iImage As Long
    End Type
    
    Public Const BIF_RETURNONLYFSDIRS = 1
    Public Const MAX_PATH = 260
    
    Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    
    Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
          
        'declare variables to be used
         Dim iNull As Integer
         Dim lpIDList As Long
         Dim lResult As Long
         Dim sPath As String
         Dim udtBI As BrowseInfo
    
        'initialise variables
         With udtBI
            .hwndOwner = hwndOwner
            .lpszTitle = lstrcat(sPrompt, "")
            .ulFlags = BIF_RETURNONLYFSDIRS
         End With
    
        'Call the browse for folder API
         lpIDList = SHBrowseForFolder(udtBI)
          
        'get the resulting string path
         If lpIDList Then
            sPath = String$(MAX_PATH, 0)
            lResult = SHGetPathFromIDList(lpIDList, sPath)
            Call CoTaskMemFree(lpIDList)
            iNull = InStr(sPath, vbNullChar)
            If iNull Then sPath = Left$(sPath, iNull - 1)
         End If
    
        'If cancel was pressed, sPath = ""
         BrowseForFolder = sPath
    
    End Function
    
    
    Form Code 
    
    Private Sub cmdServerBrowse_Click()
     txtDatabasePath.Text = BrowseForFolder(hwnd, "Please select a Server folder.")
    End Sub

    [Cimperiali colorized and indented for better reading]
    Last edited by Cimperiali; December 7th, 2002 at 05:41 AM.

  4. #4
    Join Date
    Apr 2002
    Posts
    388

    Thumbs up

    Nice!!
    mfg Ungi

    Music, music and VB. VB is like music: You never know how it is interpreted.

  5. #5
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110
    I got this from code guru sometime back

  6. #6
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    275
    thats it thanx

  7. #7
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    132
    Hi Dinesh123,

    This probably is a very simple question but can you tell me how to combine the code you gave in this thread with for example this code?

    --------------------------------------------------------------------------
    DoCmd.TransferText acExportMerge, , "Persoon", "C:\"
    --------------------------------------------------------------------------
    This code exports my database as a txt file into my C:\
    Only in stead of "C:\" I want to use the browse function.

    Many thanks,

    Jasper
    Flying is to throw yourself on the ground and miss

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Code:
    Dim strFolder as String
    strFolder= BrowseForFolder(hwnd, "Please select a Server folder.")
    If len(strFolder)>0 then
        DoCmd.TransferText acExportMerge, , "Persoon", strFolder
    End If
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  9. #9
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    132
    Hi Cimperiali,

    Pffhhhh, thank you so much. I was nearly eating my desk out of frustration there.

    Jasper
    Flying is to throw yourself on the ground and miss

  10. #10
    Join Date
    Apr 2004
    Posts
    2
    That's good,i search this code for a long time.

  11. #11
    Join Date
    Jul 2005
    Location
    Plzeň, Czech Republic
    Posts
    94

    Re: How to select a folder in common dialog control

    Is there a way, how to specify the default folder that is to be selected, when the dialog is shown?

  12. #12
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How to select a folder in common dialog control

    Quote Originally Posted by jsiii
    Is there a way, how to specify the default folder that is to be selected, when the dialog is shown?
    Yes there is!
    Code:
    CommonDialog1.InitDir = "C:\My Documents"
    CommonDialog1.ShowOpen

  13. #13
    Join Date
    Aug 2007
    Posts
    1

    Re: How to select a folder in common dialog control

    I tried and it works fine.

    The window has the title "Ordner suchen" and the buttons have the label "OK" and "Abbrechen".
    It seems that the language is taken from the system properties (I'm a german).

    Is it possible to change the language inside the window?
    I need to localize my software (changing the language in the code) without to be pressed to change the system properties.

  14. #14
    Join Date
    Sep 2007
    Posts
    4

    Re: How to select a folder in common dialog control

    thanks for coding
    but any one can give me this as a component
    it will be useful for me more than copy-paste option

  15. #15
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How to select a folder in common dialog control

    yavasoft, please do not reply to very old threads, this is the second old thread you are reviving. If you have a question, rather use the "New Thread" button on the Forum.

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

Featured