Batista
Batista

Reputation: 151

This.close() closing main form aswell

been trying to figure this out for about an hour!

I made an app that has 1 main form which is launched in Program.cs like this

frmFleetMain frmW = new frmFleetMain();
frmW.iNIPathAndFile = GlobalInfo.iNIPathAndFile;
frmW.SetUser(GlobalInfo.Username);
Application.Run(frmW);

and 1 sub form that is launched in the main form like this

                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 = "";
                }

In the btnclose event of frmsave i have this code

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:)
}

I cant figure out why this is happening!Help :)

SOLVED :

 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 = "";
                    }

}

Upvotes: 0

Views: 1103

Answers (2)

Batista
Batista

Reputation: 151

SOLVED :

 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 = "";
                    }

}

Upvotes: 0

Desolator
Desolator

Reputation: 22739

try to change frmsave.ShowDialog(); to frmsave.ShowDialog(this);

and change other code to:

        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();
        }

this works fine on my pc...

Upvotes: 1

Related Questions