I have a collection of objects that have child collection many to many linked. I want to create a child object with a dialog and then either add the child or abort the action. The code below is in the modal dialog that opens when you want to create the child and then add it to the parent collection many-to-many linked. It works fine and adds the child, but the problem is this. Below the first block of code is the code that binds the parent and child collections. The problem is one of the UI updating not reflecting the collections state properly from a user's point of view. Clicking on the parent list displays the children list nicely, but when you create a child, then associate it to the parent and click ok with the dialog, the child list will not update to reflect the added child. If i instead add() the contact to the UpToContactCollection is displays perfectly, but this method is decremented. If I use the AddNew() method of the UpToContanctCollection to create a new COntact, it reflect the contact being added to the list in the UI regardless of weather you cancel or about the action. So again the UI has garbage displayed the is not reflecting the status of the collection. How to I properly create a contact (child) entity that is not displayed in the UI untill the change is commited and saved.
Code:
m_contact.EndEdit();
m_contact.Save();
manu.AssociateContactCollection(m_contact); // This works but is decremented!! if I leave it out the UI will never diplay the new child untill the manufactureres are reloaded
manu.UpToContactCollection.Add(m_contact);
m_bs.EndEdit();
manu.Save();
Close();Code:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (bs.Count > 0)
{
m_manu = (BusinessObjects.Manufacturer)bs.Current;
this.listBox2.DataSource = m_manu.UpToContactCollection;
this.listBox2.DisplayMember = "FirstName";
}
}
Richard Young