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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
cquinn,
Is the BrowseForFolder a native Windows API?
Cheers.
Is the BrowseForFolder a native Windows API?
Cheers.
ASKER
It worked well. Thanks
Private Sub Command1_Click()
Dim wShell As Object, myFolder As Object
Set wShell = CreateObject("Shell.Applic
Set myFolder = wShell.BrowseForFolder(0, "My Dialog Title", &H1)
MsgBox myFolder.Items.Item.Path
End Sub