Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog Control to the Folder Level 1

Status
Not open for further replies.

Guygateway

Programmer
Joined
Mar 8, 2001
Messages
7
Location
US
Hello. I have used the Common Dialog Control a fair amount, especially with leading the user to a Specific File.
But now, I am developing an application, where I want the user to only go to a Specific Folder, where there will already be several Supplied Files, that are to be accessed by the program. If the user has done his part, the files will be of the same type, and named as sequential numbers, starting from 1.

Is it possible to use the Common Dialog Control to get to, and halt at, the Folder Level? If so, could you explain how? If not, could you give me another way to program this idea?

Thanks!

Guy Hurt
Guygateway@Yahoo.COM
 
The big problem with the common dialog is the lack of flexibility in this area. I have some code at work tjhat solves this issue - but it is based on some stuff from the Coomon Controls Replacement Project - so in the first instance I'll point you in that direction:

 
HI,

You can also let the user browse the folders in a treeview:
------------------------------------------------------------
Private Const BIF_STATUSTEXT = &H4&
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260

Private Const WM_USER = &H400
Private Const BFFM_INITIALIZED = 1
Private Const BFFM_SELCHANGED = 2
Private Const BFFM_SETSTATUSTEXT = (WM_USER + 100)
Private Const BFFM_SETSELECTION = (WM_USER + 102)

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long

Private 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

Private m_CurrentDirectory As String 'The current directory

Public Function BrowseForFolder(owner As Form, Title As String, StartDir As String) As String
'Opens a Treeview control that displays the directories in a computer

Dim lpIDList As Long
Dim szTitle As String
Dim sBuffer As String
Dim tBrowseInfo As BrowseInfo
m_CurrentDirectory = StartDir & vbNullChar

szTitle = Title
With tBrowseInfo
.hWndOwner = owner.hwnd
.lpszTitle = lstrcat(szTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN + BIF_STATUSTEXT
.lpfnCallback = GetAddressofFunction(AddressOf BrowseCallbackProc) 'get address of function.
End With

lpIDList = SHBrowseForFolder(tBrowseInfo)
If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
BrowseForFolder = sBuffer
Else
BrowseForFolder = ""
End If

End Function
------------------------------------------------------------

Sunaj
 
Whats wrong with a simple:

ChDir "C:\FolderThatYouWant\Folder1\Etc"
CommonDialog1.ShowOpen

Then set the Filters to show whatever file extension are desired.
 
What's wrong is that it doesn't solve the problem. Guy wants to be able to browse to, and pick a folder. The Common Dialog control always forces you to pick a file, and it is an old frustration that it has this limit.
 
Thanks for all of the help & messages. It has proven fairly useful.

Again, Thanks.

Sincerely,

Guy Hurt
Guygateway@Yahoo.COM
 
Try this instead:

Private Sub pboBrowseNewLocation_Click()
Dim i As Integer
Dim varTemp As Variant
Dim strTemp As String

On Error GoTo Cancel

CommonDialog1.Filter = "Select Directory|*.BOGUS"
CommonDialog1.FilterIndex = 1
CommonDialog1.FileName = "Select Directory"
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen

varTemp = Split(CommonDialog1.FileName, "\")
strTemp = ""

For i = 0 To UBound(varTemp) - 1
strTemp = strTemp & varTemp(i) & "\"
Next i

txtNewLocation.Text = strTemp

Cancel:
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top