I've found what's causing such behaviour. It's a bug in the .NET Framework. There is a private field on the BindingSource class:
private Dictionary<string, BindingSource> relatedBindingSources;
The problem is that once you assign null to your BindingSource.DataSource, the Dictionary remains untouched. Then you assign new DataSource, add a relation in it, the Dictionary grows. And never stops.
My solution to this problem was creating a simple method, that will assure me that all possible relations are removed:
private void ClearRelatedBindingSources(BindingSource bindingSource) {
System.Reflection.FieldInfo fi = bindingSource.GetType().GetField("relatedBindingSources", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
Dictionary<string, BindingSource> relatedBsDict = fi.GetValue(bindingSource) as Dictionary<string, BindingSource>;
if (relatedBsDict != null) {
relatedBsDict.Clear();
}
}
All there is to do is to call that method after nulling the BindingSource.DataSource property. That essentially solved the problem of band replication in my grids.
Many thanks to Thanasis thanks to whom I began to dig in the right place ;)