Results 1 to 3 of 3

Thread: [2005] folderbrowserdialog ..how to handle "close" or "cancel" button

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    [2005] folderbrowserdialog ..how to handle "close" or "cancel" button

    VB Code:
    1. dim mypath as string=""
    2. With FolderBrowserDialog1
    3.             .SelectedPath = My.Settings.defaultdir
    4.             .ShowNewFolderButton = False
    5.             .Description = "Choose your folder"
    6.             .ShowDialog()
    7.             If Len(.SelectedPath) Then mypath= .SelectedPath
    8.  End With
    9.  
    10. if mypath="" then exit sub
    11.  
    12. 'rest of code here

    i use that code to let users to select a folder.... with default directory shown when dialog is opened... but when i click on "close" or "cancel" in folderdialog....it still acts as if i selected a folder...(i.e. it continues....in the section of code).... i want it to exit sub when users pres "close" or "cancel"

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: [2005] folderbrowserdialog ..how to handle "close" or "cancel" button

    You need to get the DialogResult of the FolderBrowserDialog in your code.
    Code:
            Dim dlgResult As DialogResult
            Dim mypath As String = ""
            With FolderBrowserDialog1
                .ShowNewFolderButton = False
                .Description = "Choose your folder"
                dlgResult = .ShowDialog()
                If Len(.SelectedPath) Then mypath = .SelectedPath
            End With
            If dlgResult = Windows.Forms.DialogResult.Cancel Then
                MessageBox.Show("Dialog was cancelled")
            Else
                MessageBox.Show("Selected Folder " & mypath)
            End If
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: [2005] folderbrowserdialog ..how to handle "close" or "cancel" button

    thanks!!! trying it now!

Posting Permissions

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



Click Here to Expand Forum to Full Width