Results 1 to 4 of 4

Thread: [RESOLVED] Handling dialog box buttons

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Location
    Baltimore
    Posts
    14

    Resolved [RESOLVED] Handling dialog box buttons

    I have code that pops up a dialog box and waits for either the OK or Cancel button to be clicked. I am trying to figure out how to get and use the repsonse from dialog box. If the user clicks OK, I want the rest of the code to execute normally (it already does this by default). If the user clicks Cancel, I want to skip the rest of the code. I was assuming OK would return TRUE and Cancel would return FALSE, but that apparently is not correct. How do I figure out whether OK or Cancel was clicked?

    Code:
            If Not MapCheck() = "" Then
                DiaError.TextBoxErr.Text = MapCheck()
                If Not DiaError.ShowDialog() Then  'show dialog box and evaluate output
                    GoTo breakme 'if Cancel is clicked
                End If
            End If
    
            ' Rest of code

  2. #2
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Handling dialog box buttons

    Instead of:

    Code:
         If Not DiaError.ShowDialog() Then  'show dialog box and evaluate output
                    GoTo breakme 'if Cancel is clicked
                End If
    use this instead:

    Code:
    Select Case DiaError.ShowDialog()   'test the dialogresult
        Case OK 'edit this for the proper variable
    
        Case Cancel 'edit this for the proper variable
    
    End Select

  3. #3
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: Handling dialog box buttons

    Quote Originally Posted by j-aero View Post
    I have code that pops up a dialog box and waits for either the OK or Cancel button to be clicked. I am trying to figure out how to get and use the repsonse from dialog box. If the user clicks OK, I want the rest of the code to execute normally (it already does this by default). If the user clicks Cancel, I want to skip the rest of the code. I was assuming OK would return TRUE and Cancel would return FALSE, but that apparently is not correct. How do I figure out whether OK or Cancel was clicked?

    Code:
            If Not MapCheck() = "" Then
                DiaError.TextBoxErr.Text = MapCheck()
                If Not DiaError.ShowDialog() Then  'show dialog box and evaluate output
                    GoTo breakme 'if Cancel is clicked
                End If
            End If
    
            ' Rest of code
    Here's what I did to confirm clearing all nodes in a TreeView...

    vb.net Code:
    1. Dim ConfirmClear As DialogResult
    2. ConfirmClear = MessageBox.Show("Are you sure that you wish to clear all events?", "Confirm Clear Play Sequence", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
    3.  
    4. If ConfirmClear = DialogResult.Yes Then
    5.     tvwPlaySequence.Nodes.Clear()
    6. End If

    Adapt for your situation.
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Location
    Baltimore
    Posts
    14

    Re: Handling dialog box buttons

    Thanks. I used Campion's recommendation.

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