I have a business object, which is a composite of child objects.
I am using databinding in Visual Studio 2008 to bind to controls on a Windows form.
But I am getting the above error in the InitializeComponent method of the form.
Lets say I have an object called ParentObject which contains a generic list, ChildListObject. The ParentObject also has Child object, which itself has a Child object. (ie ParentObject.ChildObject.ChildObject)
I set the main binding source:
BindingSource.Datasource = ParentObject
I add a grid and set it's binding source:
GridBindingSource.Datasource = ParentObject
and set the DataMember to:
BindingSourceB.DataMember = "ChildListObject"
Now, the grid's datasource is set to GridBindingSource:
Me.MyDataGridView.DataSource = Me.GridBindingSource
There are also other controls that are bound to properties of the ParentObject and the ParentObject.ChildObject
I have tested this in an isolated project and it works fine, so I am having trouble finding out what the real bug is? Code that used to work, will all of the sudden stop working.
The error I get is (if I use the names of the objects in the above example):
"DataMember property ChildObject cannot be found on the DataSource"
It fails on:
Me.MyDataGridView.DataSource = Me.GridBindingSource
Strangely, if I remove <System.Diagnostics.DebuggerStepThrough()> and then when it fails just continue it is fine??? But it still fails in runtime.
Does anyone have any ideas that could point me in the right direction? The closest I have found through googling is it may have something to do with the order of the generated designer code getting messed up. Code that was working, will all of the sudden stop working.
This issue seems to come and go. If I just continue after the error is raised the program happily continues with no problems. Possibly a bug in VS. But at run-time the error still exists.
What is causing this problem? How do I stop it occurring?
I tried several experiments on this. The problem only happens in this condition
if you have a BaseForm and BindingSource on it,
if you inherit a new InheritedForm from this BaseForm,
or
if you have additional binding source on InheritedForm related to the BindingSource (which inherited by BaseForm)
you have the designer error. I don't have a designer solution but if you simply ignore and continue everything is going to be normal when you build project again
or you will have to set the datamember by code.