Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello everybody i have some code when form is cloasing. In this form is a btnOK which is make something and then closing form. how to switch off following code when user press the btnOK (in if)

private void Sell_FormClosing(object sender, FormClosingEventArgs e)
{

    if (dgvProducts.Rows != null )
    {
        if (MessageBox.Show("do u really want to close?", "attention", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
        {
            e.Cancel = false;
        }
        else
        {
            e.Cancel = true;
        }
    }

}
Posted
Updated 6-Nov-10 0:49am
v2
Comments
OriginalGriff 6-Nov-10 6:49am    
Sorry, what are you trying to ask? What following code are you trying to avoid executing?
Is it:
1) Code following the if(MessageBox...) else... section?
2) Code following the if(dgvPro...)... section?
3) Code following the Form.Close() in your btnOK handler?
4) Something else completely?

Please edit your question and clarify it so we can help you!
shakil0304003 6-Nov-10 10:28am    
Not Clear!!!

1 solution

C#
private void Sell_FormClosing(object sender, FormClosingEventArgs e)
{
    if (this.DialogResult == false)
    {
        if (dgvProducts.Rows != null )
        {
            e.Cancel = (MessageBox.Show("do u really want to close?", "attention", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes);
        }
    }
}
 
Share this answer
 

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