Parent-child binding question

Parent-child binding question

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


fredg posted on Friday, January 27, 2012

In the ProjectEdit control sample, the parent is bound to a form, and the child collection is bound to a datagrid. So the RebindUI() looks like: 

 

private void RebindUI(bool saveObject, bool rebind)
{   
  this.projectBindingSource.RaiseListChangedEvents = false;
  this.resourcesBindingSource.RaiseListChangedEvents = false;
  try
  {    
   UnbindBindingSource(this.resourcesBindingSource, saveObject, false);
   UnbindBindingSource(this.projectBindingSource, saveObject, true);
       .............
  }
}

   My question is: if the UI only contains a datagrid which is bound to child collection and parent object is NOT bound to any control/form, can we reduce the above code to the following and do NOT need to care about parent bindingsource?

 private void RebindUI(bool saveObject, bool rebind)  
 {
 this.resourcesBindingSource.RaiseListChangedEvents = false;
 try
 {
   UnbindBindingSource(this.resourcesBindingSource, saveObject, false);
      ......
 }
}

        

JonnyBee replied on Friday, January 27, 2012

Hi,

Yes, you are not required to bind the parent to a BindngSource when the parent is not used for any databinding in the UI.

Copyright (c) Marimer LLC