Results 1 to 15 of 15

Thread: FolderBrowserDialog Problem

  1. #1
    aeskan is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2011
    Posts
    54
    Reputation
    25

    Exclamation FolderBrowserDialog Problem

    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!

    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.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,336
    Reputation
    1543
    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

  3. #3
    aeskan is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2011
    Posts
    54
    Reputation
    25
    Any idea still will be appreciated.

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,186
    Reputation
    2368
    Quote Originally Posted by aeskan View Post
    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
    That is the standard behaviour, see the remarks: FolderBrowserDialog.SelectedPath Property (System.Windows.Forms)

  5. #5
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,336
    Reputation
    1543
    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.

  6. #6
    aeskan is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2011
    Posts
    54
    Reputation
    25
    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 by aeskan; 05-27-2012 at 6:14 PM.

  7. #7
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,186
    Reputation
    2368
    If you want user to browse for files maybe you should consider OpenFileDialog component?

  8. #8
    aeskan is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2011
    Posts
    54
    Reputation
    25
    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 by aeskan; 05-27-2012 at 8:24 PM.

  9. #9
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,336
    Reputation
    1543

  10. #10
    aeskan is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2011
    Posts
    54
    Reputation
    25
    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'.

  11. #11
    aeskan is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2011
    Posts
    54
    Reputation
    25
    It accepts FolderNameEditor as Inherits, but FolderNameEditor does not support HookProc!

    Error 1 'HookProc' is not a member of 'System.Windows.Forms.Design.FolderNameEditor'.

  12. #12
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,336
    Reputation
    1543
    Quote Originally Posted by aeskan View Post
    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.

  13. #13
    aeskan is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2011
    Posts
    54
    Reputation
    25
    No matter buddy. thank you anyway.

  14. #14
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,186
    Reputation
    2368
    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.

  15. #15
    aeskan is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2011
    Posts
    54
    Reputation
    25
    Quote Originally Posted by JohnH View Post
    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.

    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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking