Link to home
Start Free TrialLog in
Avatar of khaledc
khaledc

asked on

Directory Selection Control

Dear All,

I am using VB6 and usually to I use the MS Common Dialog control to save and open file. However, I only need to locate a directory and I would like to know if the MS Common Dialog control can still be used with some special settings to the its flags property (or any other property).

Note that I have a third party control that does the job but I would like to keep my controls native to VB.

Your help is appreciated.

Regards.
ASKER CERTIFIED SOLUTION
Avatar of cquinn
cquinn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vinnyd79
vinnyd79


Private Sub Command1_Click()
Dim wShell As Object, myFolder As Object
Set wShell = CreateObject("Shell.Application")
Set myFolder = wShell.BrowseForFolder(0, "My Dialog Title", &H1)
MsgBox myFolder.Items.Item.Path

End Sub
The easiest thing to do is create your own form.

Add a DriveListBox... and a DirListBox (standard VB6 Controls).  The click on the DriveListBox refereshes the DirListBox and then a "Save" button would return the selected directory path.

Example:   (you can make the form look however you want...)
DriveListBox (named Drive1)
DirListBox (named Dir1)
CommandButton (named cmdOK)

Code on the form:
Public lcPath
Public Event PathSelected(PathName As String)

Private Sub cmdOK_Click()
   
    If UCase(Left$(Dir1.path, 1)) <> UCase(Left$(Drive1.Drive, 1)) Then
        lcPath = Drive1.Drive & "\"
    Else
        lcPath = Dir1.path
    End If
    RaiseEvent PathSelected(CStr(lcPath))
    Unload Me
   
End Sub

Private Sub Drive1_Change()

    Dir1.path = Drive1.Drive
    Dir1.Refresh

End Sub

Private Sub Form_Load()

    On Error Resume Next
   
    If lcPath = "" Then
        Drive1.Drive = App.path
        Dir1.path = App.path
    Else
        Drive1.Drive = lcPath
        Dir1.path = lcPath
    End If

End Sub



Avatar of khaledc

ASKER

cquinn,

Is the BrowseForFolder a native Windows API?

Cheers.
Avatar of khaledc

ASKER

It worked well. Thanks