一直试图解决这个问题大约一个小时!
我创建了一个有一个主要表单的应用程序,它在Program.cs中启动,就像这样
frmFleetMain frmW = new frmFleetMain();
frmW.iNIPathAndFile = GlobalInfo.iNIPathAndFile;
frmW.SetUser(GlobalInfo.Username);
Application.Run(frmW);
和在主窗体中启动的1个子窗体,如下所示
if (recordid != "")
{
frmFleetSave frmsave = new frmFleetSave();
frmsave.Rowid = int.Parse(recordid);
frmsave.ShowDialog();
dgvMain.Rows[rowindx].Cells[0].Style.BackColor = Color.Red;
oFuel.Filter = FLEET_FUEL.ColumnNames.FUEL_SEQUENCE + " = "+recordid;
oFuel.FLEET_NO = int.Parse(GlobalInfo.FLEETNO);
oFuel.Filter = "";
GlobalInfo.FLEETNO = "";
}
在frmsave的btnclose事件中,我有这段代码
if (GlobalInfo.FLEETNO == "")
{
DialogResult result = MessageBox.Show("Record will not be updated!Click OK to try again or CANCEL to close.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.Cancel)
{
this.Close();//this closes both forms -this is not what i want
}
}
else
{
this.Close();//this closes frmsave only-this is what i want:)
}
我无法弄清楚为什么会发生这种情况!帮助:)
求助:
if (recordid != "")
{
frmFleetSave frmsave = new frmFleetSave();
frmsave.Rowid = int.Parse(recordid);
frmsave.ShowDialog();
if (frmsave.ssave)//get a bool variable indicating we can save! :-P
{
oFuel.Filter = FLEET_FUEL.ColumnNames.FUEL_SEQUENCE + " = " + recordid;
oFuel.FLEET_NO = int.Parse(GlobalInfo.FLEETNO);
oFuel.Filter = "";
GlobalInfo.FLEETNO = "";
}
}
答案 0 :(得分:1)
尝试将frmsave.ShowDialog();
更改为frmsave.ShowDialog(this);
并将其他代码更改为:
DialogResult result = MessageBox.Show(this, "Record will not be updated!Click OK to try again or CANCEL to close.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.Cancel)
{
Close();
}
这在我的电脑上工作正常......
答案 1 :(得分:0)
求助:
if (recordid != "")
{
frmFleetSave frmsave = new frmFleetSave();
frmsave.Rowid = int.Parse(recordid);
frmsave.ShowDialog();
if (frmsave.ssave)//get a bool variable indicating we can save! :-P
{
oFuel.Filter = FLEET_FUEL.ColumnNames.FUEL_SEQUENCE + " = " + recordid;
oFuel.FLEET_NO = int.Parse(GlobalInfo.FLEETNO);
oFuel.Filter = "";
GlobalInfo.FLEETNO = "";
}
}