Home > DeveloperSection > Forums > Catching MessageBox result
Chintoo Semi

Total Post:135

Points:947
Posted on    October-04-2013 9:19 AM

 C# C# 
Ratings:


 1 Reply(s)
 634  View(s)
Rate this:

I'm trying to get the user to confirm if they want to delete a product using a MessageBox and catching its result. This is my code:

 

// Confirm if the user really wants to delete the product

DialogResult result = MessageBox.Show("Do you really want to delete the product \"" + productName + "\"?", "Confirm product deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

if (result == DialogResult.OK)

{

    MessageBox.Show("deleted");

}

When I run the code and try to delete a product, deleted never shows. On the MSDN page it says to use MessageBoxResult rather than DialogResult but Visual Studio doesn't recognise MessageBoxResult, and I use DialogResult elsewhere in my code for an open file dialog. Obviously, that's not the proper way to check it.



jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    October-04-2013 9:31 AM

You must ask for DialogResult.Yes

// Confirm if the user really wants to delete the product

DialogResult result = MessageBox.Show("Do you really want to delete the product \"" +     productName + "\"?", "Confirm product deletion", MessageBoxButtons.YesNoMessageBoxIcon.Warning);

if (result == DialogResult.Yes)

{

    MessageBox.Show("deleted");


Modified On Mar-15-2016 05:51:02 AM

Don't want to miss updates? Please click the below button!

Follow MindStick