Apologies for the bad title, hard to sum up.
So what is happening is I am have a form that will load data from the database:
JobModel jobModel = Data.GetJobList(model)[0];
JobModel contains a field for a list of "parts" also known as a "PartModel"
public class JobModel
{
...
public List<PartModel> parts { get; set; }
...
}
So when a user loads up the form I save the data before they begin data entry by assigning this global JobModel to refer back to in later segments of the code. Also the partsModel is located here as well
public static JobModel previousJobModel = new JobModel();
public static List<PartModel> partModels = new List<PartModel>();
public void LoadFormData(int JobID)
{
...
JobModel jobModel = Data.GetJobList(model)[0];
partModels = jobModel.parts;
previousJobModel = jobModel;
...
}
Now what happens is that during a segment of code, the previousJobModel.parts becomes overwritten when the DELETE section of code is executed
private void olvJobPartList_RightClick(object sender, BrightIdeasSoftware.CellRightClickEventArgs e)
{
PartModel model = (PartModel)e.Model;
if (model != null)
{
selectedModel = model;
menuStripOLV.Show(Cursor.Position);
}
}
private void deletePartToolStripMenuItem_Click(object sender, EventArgs e)
{
//previousJobModel.parts Count = 7
var itemToRemove = partModels.Single(r => r.PartNumber == selectedModel.PartNumber && r.partID ==
selectedModel.partID);
partModels.Remove(itemToRemove);
//previousJobModel.parts Count = 6
populateOLV();
}
Few notes: I did put a couple breakpoints in the "delete" function, before the removal of the part from the list, previousJobModel is normal, after it gets screwed up. I am also getting back into the swing of things with coding in general so I may be missing something dumb here. Also changing other fields within the job causes no issues to the previous job model, only deleting a part from the list