日期:2014-05-18  浏览次数:20805 次

我的一个实例,看一下吧
我用我的事例改的绝对可以运行!!!!!
private void EXIT_Click(object sender, EventArgs e)
  {
  DialogResult a = MessageBox.Show("您还没有保存数据,是否要保存?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
  if (a != DialogResult.Yes)
  {
  this.Validate();
  this.userInfoBindingSource.EndEdit();
  this.userInfoTableAdapter.Update(this.gameCardSaleDataSet2.UserInfo);
  this.Close(); /////////////////////为何不能关闭窗体????? 
   
  }
  else
  {
  this.Close();
  }
  }
 

------解决方案--------------------
写反了。

等于yes的时候保存。
------解决方案--------------------
问题出在
this.userInfoBindingSource.EndEdit();
this.userInfoTableAdapter.Update(this.gameCardSaleDataSet2.UserInfo);
这个上面,你把这2句注释了,能正确关闭的
------解决方案--------------------
this.ShowDialog();
Application.Exit();
------解决方案--------------------
表示 没有看出来有什么不对劲的、、正如二楼所说 还有
你的代码可以精简一下

if (a != DialogResult.Yes)
{
this.Validate();
this.userInfoBindingSource.EndEdit();
this.userInfoTableAdapter.Update(this.gameCardSaleDataSet2.UserInfo);
this.Close(); /////////////////////为何不能关闭窗体?????

}
else
{
this.Close();
}
 如下:
if (a != DialogResult.Yes)
{
this.Validate();
this.userInfoBindingSource.EndEdit();
this.userInfoTableAdapter.Update(this.gameCardSaleDataSet2.UserInfo);
}
this.Close();
反正什么操作你都要关闭窗体的、、只是判断关闭前 执行操作否