Issue adding grandchild to child

Issue adding grandchild to child

Old forum URL: forums.lhotka.net/forums/t/10514.aspx


JasonG posted on Monday, July 11, 2011

Following Rocky's suggestion I created an "add" method in my grandchild collection...

public void Add(Guid id)
{
if(!(Contains(id))
{
  int before = this.Count; 

  grandchild child = grandchild.NewGrandChild(id);

  this.Add(child);  
 
  int after = this.Count;
 }

}

when I call the Add methd and check the "before" and "after" all looks ok. "after" = "before" + 1.

but.. 

private void addGrandChildButton_Click(object sender, EventArgs e)
{
 ChildSelect dlg = new ChildSelect(); 
 if(dlg.ShowDialog() == DialogResult.OK)  
 try
 {   
   _congregation.Speakers[currentIndex].Talks.Add(dlg.id);
  int count = _parent.Children[currentIndex].GrandChildren.Count;
 }

}

When i check the count here there is no change. It is as if no grandchildren were added..

Does anyone have any idea why, or what the problem could be?

thanks,

Jason

 

 

JasonG replied on Thursday, July 21, 2011

I havn't been able to find the source of this problem yet. But i didn't uncover another problem that is probably related.

Changes to my Child ojects are not saving. I noticed that when i check my parent oject, the child that i just changed doesn't have the changes that i just made on the UI. But if i look at the child object in the childBindingsource the changes are there. So there seems to  be a dissconnect between my parent object and the child binding soure.

I've deleted the child bindingsource and added a new one. Same issue.

Any ideas?

 

JasonG replied on Friday, July 22, 2011

Update :

in order to get this to work i had to add this line of code to my BindUI() method. I shouldn't need it, but it doesn't work without it.

this.chidrenBindingSource.DataSource = _parent.Children;

Copyright (c) Marimer LLC