[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
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
Re: Handling dialog box buttons
Quote:
Originally Posted by
j-aero
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:
Dim ConfirmClear As DialogResult
ConfirmClear = MessageBox.Show("Are you sure that you wish to clear all events?", "Confirm Clear Play Sequence", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If ConfirmClear = DialogResult.Yes Then
tvwPlaySequence.Nodes.Clear()
End If
Adapt for your situation.
Re: Handling dialog box buttons
Thanks. I used Campion's recommendation.