Question FolderBrowserDialog Problem

aeskan

Well-known member
Joined
Aug 10, 2011
Messages
63
Programming Experience
3-5
Hi everbody,

I'm just wondering why VB.Net FolderBrowserDialog control have no event handler (same as SelectionChanged and etc.) to handle some events if necessary!:angryfire:

The problem is unlike VB6 which we could handle events same as SelectionChanged in BrowseFF control to disable or enable Ok button if the Selected Path was null or empty, here in VB.Net I have not found any way to do that. Years ago in VB6 we simply used to write following codes and it was finshed:

Private Sub BrowseFF1_SelectionChanged(CurrentItem As MBBrowse.ShellItem, OKEnabled As Boolean)
If CurrentItem.fullPath = "" Then
OKEnabled = False
Else
OKEnabled = True
End If
End Sub

But now I'm confused! Should I write a new class for it and declare new event handler, or what? Any idea will be appreciated previously. thnx.:D
 
The FolderBrwoserDialog is actually a .NET wrapper for a Win32 dialogue, which is the same dialogue that VB6 would use. As such, the functionality you want is in there. It's just a matter of getting at it. Here's an example of the sort of thing you would need to do:

Customising Common Dialogues
 
I didn't actually read that "was null or empty" part correctly but I'm not sure it was written properly either. I interpreted the question to mean that the OK button was to be disabled if you didn't want the user to be able to open the selected folder, e.g. if that folder contained no files.
 
Dear jmcilhinney and Dear JohnH,

Have you ever seen sometimes in a FolderBrowseDialog (for example browsing for windows driver files to install) when you click on a folder that does not contain the specific file the Ok button gets disabled and inversely when you click on a folder that contains the specific file Ok button gets enabled? In my mentioned example you could do it as below:

Private Sub BrowseFF1_SelectionChanged(CurrentItem As MBBrowse.ShellItem, OKEnabled As Boolean)
If Dir(CurrentItem.fullPath & "\Driver.dll) <> "" Then
OKEnabled = True
Else
OKEnabled = False
End If
End Sub

Well, thankfully in your posts I didn't find my answer honestly. Link that JohnH mentioned, says "If the user selects a folder that does not have a physical path (for example, My Computer), the OK button on the dialog box will be disabled", but that's not my case! And also in the jmcilhinney's former post, of course we could write any codes for predefined Types, Constants, Methods and etc., but there is not any way to add my needfull Events! Maybe I've forgot something or do not know something that is reqiured!

Thank you.
 
Last edited:
If you want user to browse for files maybe you should consider OpenFileDialog component?
 
I want user to browse for folder that contains specific file(s). Imagine you are writing codes that user could restore backuped files from selected folder, and meantime wanting to disable Ok button if folder is miscellaneous, empty or contains unknown files instead of your passable files. Users actually do not know which files are the backup files (programmer knows), they only know the folder that they have backuped to. So you should prohibit users to restore unwelcome files to your program accidentally. I know that I can check the selected folder's files after pressing Ok button by user and throw an error message, but developing means programming and tools evolution!

Thanks for your pursuit.
 
Last edited:
It works with ColorDialog, but does not work with FolderBrowserDialog because it is not Inheritable!

Imports
System.Runtime.InteropServices
Public Class FolderBrowserEx
Inherits FolderBrowserDialog
End Class

Error 1 'FolderBrowseEx' cannot inherit from class 'FolderBrowserDialog' because 'FolderBrowserDialog' is declared 'NotInheritable'.
 
It accepts FolderNameEditor as Inherits, but FolderNameEditor does not support HookProc!

Error 1 'HookProc' is not a member of 'System.Windows.Forms.Design.FolderNameEditor'.
 
It works with ColorDialog, but does not work with FolderBrowserDialog because it is not Inheritable!

Imports
System.Runtime.InteropServices
Public Class FolderBrowserEx
Inherits FolderBrowserDialog
End Class

Error 1 'FolderBrowseEx' cannot inherit from class 'FolderBrowserDialog' because 'FolderBrowserDialog' is declared 'NotInheritable'.

B*gger! That I didn't realise. Sorry about that.
 
One option is to write a class derived from CommonDialog class (the base class of FolderBrowserDialog), use .Net Reflector to get the code that FolderBrowserDialog adds, then modify that to suit your needs. FolderBrowserDialog mostly deals with the native SHBrowseForFolder function.
 
One option is to write a class derived from CommonDialog class (the base class of FolderBrowserDialog), use .Net Reflector to get the code that FolderBrowserDialog adds, then modify that to suit your needs. FolderBrowserDialog mostly deals with the native SHBrowseForFolder function.

Yep! SHBrowseForFolder Works. It has a CallBack function to customize the browser's behaviors. Thank you. :stung:

People who wants download the code in VS 2002 can go to SHBrowseForFolder Implementation Class by Seth Mitchell
and for more comprehensive information can see VBnet™ Visual Basic Developers Resource Centre
 
Back
Top