Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a generic collection

Status
Not open for further replies.

ChewDoggie

Programmer
Mar 14, 2005
604
US
Hello All,

I have a generic collection in a child Windows form and I need to pass the collection to the parent form. Does anyone know how to do this seemingly simple thing ?

I have a FormClosingEventHandler in the parent form that has the following code:

Code:
private void MyFormClosingHandler(object sender, FormClosingEventArgs e)
{
    Form F = (Form)sender;
    if (F.Name == "frmEditCompany")
    {
        // objSelectedCompany is an object in the parent form and it has a collection of CompanyDepartments. I clear them all out because I want to rebuild the collection from the edited collection in the child form
        objSelectedCompany.CompanyDepartments.Clear();
        // EditCompanyForm is the child form and CompDepts is the generic collection in that form.  I want to pass THIS collection to the collection in the parent object.
        foreach (clsDepartment D in EditCompanyForm.CompDepts)
        {
            objSelectedCompany.CompanyDepartments.Add(D);
        }
    }
}

Anyhow, after I execute this code, the two collections (objSelectedCompany.CompanyDepartments (Parent Form) AND
EditCompanyForm.CompDepts (Child Form)) should match and they don't.

The only thing I can think of is that each CompanyDepartment has a collection of "CompanyShifts" and that collection is popuated with the number of shifts. Does that collection have to be removed prior to doing something with the Departments ?

If anyone sees something I'm missing, please let me know.


Chew

10% of your life is what happens to you. 90% of your life is how you deal with it.
 
I figured this out.

The property in the objSelectedCompany prepopulated the Department list every time it was called and that's why the two lists didn't match.

Chew

10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top