读书人

小弟我的一个实例看一下吧

发布时间: 2012-06-20 20:37:21 作者: rapoo

我的一个实例,看一下吧
我用我的事例改的绝对可以运行!!!!!
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();
反正什么操作你都要关闭窗体的、、只是判断关闭前 执行操作否

读书人网 >C#

热点推荐