468,301 Members | 1,532 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

Ability to select a folder path

2
Hi Everyone,

I am working in VB6 and am trying to get code that would allow a user to select a folder path. I was using the OpenFileDialog control but it doesn't work for selecting folders, only if you want to select a file.

There was someone on here before who mentioned he was able to accomplish by using an OCX called DPDLG...so I know it works somehow but I am not sure how this is done.

If anyoen could provide any help...any sample code...it would be greatly appreciated.
Nov 8 '06 #1
7 25752
albertw
267 100+
Hi Everyone,

I am working in VB6 and am trying to get code that would allow a user to select a folder path. I was using the OpenFileDialog control but it doesn't work for selecting folders, only if you want to select a file.

There was someone on here before who mentioned he was able to accomplish by using an OCX called DPDLG...so I know it works somehow but I am not sure how this is done.

If anyoen could provide any help...any sample code...it would be greatly appreciated.
hi

seems nasty, try using a dirlistbox for a change and have the clicked directory displayed in a label or textbox
Nov 8 '06 #2
tlove
2
hi

seems nasty, try using a dirlistbox for a change and have the clicked directory displayed in a label or textbox
Thank you very much for your help! Using the dirlistbox solved the problem. I appreciate it.
Nov 9 '06 #3
Killer42
8,434 Expert 8TB
Thank you very much for your help! Using the dirlistbox solved the problem. I appreciate it.
I see you have what you wanted. But for you or anyone else who is looking for alternatives, you might try the following links. I believe it is possible to use the standard Windows selection dialogue, which generally provides a nicer user experience than a dirlistbox. Hopefully, one or more of these will show how (haven't had time to check them out yet).
Nov 9 '06 #4
albertw
267 100+
hi

display a select folder dialog is actually a great solution

make a reference in your code to shell32.dll (system32)
put

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private shlShell As Shell32.Shell
  3. Private shlFolder As Shell32.Folder
  4. Private Const BIF_RETURNONLYFSDIRS = &H1
  5.  
  6.  
in your general declaration

and use

Expand|Select|Wrap|Line Numbers
  1.  
  2. Set shlShell = New Shell32.Shell
  3. Set shlFolder = shlShell.BrowseForFolder(Me.hWnd, "Select a Folder",BIF_RETURNONLYFSDIRS)
  4.  
  5.  
to call the folder dialog
simple but functional
Nov 10 '06 #5
samycbe
83
hi

how to add the dirlist component in the project?.........
Apr 9 '07 #6
Killer42
8,434 Expert 8TB
how to add the dirlist component in the project?.........
In VB6, the DirListBox control is one of the standard ones - it doesn't need to be added to the project. In the toolbox, it's a yellow folder icon.

(Possibly it's only available in the Professional and Enterprise Editions, but I don't think so.)
Apr 9 '07 #7
Hi Everyone,

I am working in VB6 and am trying to get code that would allow a user to select a folder path. I was using the OpenFileDialog control but it doesn't work for selecting folders, only if you want to select a file.

There was someone on here before who mentioned he was able to accomplish by using an OCX called DPDLG...so I know it works somehow but I am not sure how this is done.

If anyoen could provide any help...any sample code...it would be greatly appreciated.
Hello,
You can solve your Problem using your in build control.rather then using
API call.I am using Drivelist,Dirlist form control and using a label to select a folder.however in VB 2005 we can browse folder like file but in vb 6 we don't.
All though I have coded this sample in VB 2005. you can use it in vb 6 with some changes
VB 2005 CODE SAMPLE.
Expand|Select|Wrap|Line Numbers
  1. Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChanged
  2.         DirListBox1.Path = DriveListBox1.Drive
  3.         Label1.Text = DirListBox1.Path
  4.     End Sub
  5.  
  6.  
  7.  
  8.     Private Sub DirListBox1_Change(ByVal sender As Object, ByVal e As System.EventArgs) Handles DirListBox1.Change
  9.         Label1.Text = DirListBox1.Path
  10.     End Sub
  11.  
Ok buddy I write the VB 6 code.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Dir1_Change()
  2.  Label1.Caption = Dir1.Path
  3. End Sub
  4.  
  5. Private Sub Drive1_Change()
  6. Dir1.Path = Drive1.Drive
  7. Label1.Caption = Dir1.Path
  8. End Sub
  9.  
I think this code fulfill your requrement .Good luck.
Apr 11 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Chung | last post: by
2 posts views Thread by Harshdeep Mehta | last post: by
5 posts views Thread by John A Grandy | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.