BindingSource set DataSource and DataMember atomically?

D

Doug Crawford

I have a hierarchical structure of objects that I am using with Data
Binding. My "Application" class contains a public property named
"Status" which returns my "Status" object. I have a UserControl with
applicationBindingSource and statusBindingSource components. I am using
the VS designer to link both binding sources to various labels on my
control.

I run into problems when I set the DataSource and DataMember properties
after the InitializeComponent() call. The constructor looks like:

InitializeComponent();
applicationBindingSource.DataSource = MyApplication;
statusBindingSource.DataSource = applicationBindingSource;
statusBindingSource.DataMember = "Status";

The problem is that as soon as I set statusBindingSource.DataSource I
get an exception indicating that the DataSource was unable to bind to
the first label I have wired in the designer. I thought perhaps I need
to set statusBindingSource.DataMember first, but when I do this I get an
exception saying "DataMember property 'Status' can not be found on the
DataSource".

Interestingly, if I remove all bindings to my Labels in the VS designer
and manually set up my DataBindings after I have set
statusBindingSource.DataSource then everything works fine. It appears
like I need some way to set the DataSource and DataMemeber in one atomic
step. Also, this problem is only an issue on the compact framework.
The same code runs fine on the full framework.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top