I have a MDI application. One of the forms needs to be able to have multiple instances of it open at the same time. Within this app I have a Program class. For each instance of the form I need to place a Program object into each form. This is working, however, everytime data is changed it changes all of the Program objects within all of the multiple instances of the form.
Here is the Program class (very simple class for now):
public class Program
{
string strProgramCode;
public Program()
{ }
public string ProgramCode
{
get { return strProgramCode; }
set { strProgramCode = value; }
}
}
Here is the code for the form:
frmWeeklyIndividualBudgets tfrmWeeklyIndividualBudgets = new frmWeeklyIndividualBudgets();
tfrmWeeklyIndividualBudgets.Program = this.Program;
tfrmWeeklyIndividualBudgets.Text = this.Program.ProgramCode.ToString() + " Weekly Budget";
this.CheckMdiChildren(tfrmWeeklyIndividualBudgets);
Here is the CheckMdiChildren method:
private void CheckMdiChildren(Form form)
{
foreach (Form frm in this.MdiChildren)
{
if (frm.GetType() == form.GetType())
{
if (frm.GetType().ToString() == "IPAMFinancial_Program_Financial_Breakdown.frmWeeklyIndividualBudgets")
{
frmWeeklyIndividualBudgets tfrm = (frmWeeklyIndividualBudgets)frm;
if (tfrm.Program.ProgramCode == this.Program.ProgramCode)
{
frm.Focus();
return;
}
}
else
{
frm.Focus();
return;
}
}
}
form.MdiParent = this;
form.Show();
}