I'm using typed dataset in winforms app, .net 3.5 (VS 2010). A form has DataGridView. In FormClosing event I ask user to save changes. If user doesn't want to save I'd like to let the from close. However, when DataGridView has validation errors (I validate dataset in datatables's ColumnChanging event) the form won't close. Even if I do not catch FormCLosing event the form refuses to close. I guess I have to clear validation errors in datagridvIew somehow. Can someone suggest a solution?

Edit: One more detail: the form is mdi child form. Needless to say, mdi parent won't close also.

有帮助吗?

解决方案 2

Ok, it was my mistake. mdi parent had some handlers for mdi child events, but when the child form closed not all handlers were removed.

其他提示

You may override validation and (force close) close the form the by setting false to FormClosingEventArgs.Cancel property of Closing handler argument.

 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
     DialogResult res = MessageBox.Show("Close it?", "Close", MessageBoxButtons.YesNo);
     if (res == DialogResult.No)
     {
       e.Cancel = true;
     }
     else
     {
        e.Cancel = false;
      }
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top