Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anyone teach me how i can determine if 'yes' or 'no' has been clicked on a message box? my code is as shown below:
C#
MessageBox.Show("Applicant already has interview date. Do you want to overwrite this date?", "Set interview", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    if (DialogResult.Yes)
    {
        sql = "insert into interview(FileLoc, date, time) values('" + id + "', '" + intdate.Text.ToString() + "', '" + inttime.Text.ToString() + "')";
        cmd.ExecuteNonQuery();
    }
Posted
Updated 25-Jan-11 7:31am
v2

1 solution

Capture the return value from the Show method and test against the DialogResult enum

C#
DialogResult result = MessageBox.Show("Applicant already has interview date. Do you want to overwrite this date?", "Set interview", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if(result == DialogResult.Yes)
{
}
 
Share this answer
 
Comments
[no name] 24-Jan-11 7:47am    
thanks
Sergey Alexandrovich Kryukov 24-Jan-11 11:19am    
OP never reads API help or what?
You got 5.
Richard MacCutchan 25-Jan-11 16:57pm    
If they did read it CodeProject would be a quiet place!
fjdiewornncalwe 25-Jan-11 14:05pm    
+5. Simple and clean...
GenJerDan 25-Jan-11 14:21pm    
Or even if (MessageBox.Show("Applicant already has interview date. Do you want to overwrite this date?", "Set interview", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { }

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900