BindingSource, Custom DataSource and DataGridView driving me mad!

S

Steve

Hi-

OK, I've got a DataGridView, I've created a BindingSource from one of my
Business Entity object (based on generated classes from EntitySpaces) I've
left the default column setup so that all the columns are displayed.

My DataSource objects are composed like this:

class Customer : esCustomer // where esCustomer is the EntitySpaces class
that was generated
{
public string PropTest
{
get{ return "PropTest!"; }
}
}


esCustomer has some properties as well that were generated from my DB
schema, but from what I can see from teh code.. that shouldn't matter.

The problem is, all the properties that are in esCustomer are bound to the
DataGridView correctly, however none of the properties I add to Customer are
displayed.
I have checked and double checked that I'm indeed using the correct class
for the BindingSource object.

I've searched for events that I can subscribe to so I can try and debug the
binding process, but I'm not seeing anything that appears to expose the code
that is trying to fetch the properties.

I'm stuck and frustrated. Anyone want to suggest anything I should try?

Thanks for reading,
Steve Klett
 
S

Stoitcho Goutsev \(100\)

Steve,

Did you actually write a code to bind the binding source to an instance of
your Customer class. This is not done by the designer. The designer uses the
class to initialize the datagirdview, but doesn generate code to bind the
binding source to actuall instance of that class. It can do that because it
doesn't know where to get this instance from.

If you look at the InitializeComponent method you'll see that the binding
source is actually set up with the Type object of your class. This doesn do
much at run time.

What you need to do is in your form constructor or in some other place in
your code after the InitialzeComponent is called you need to add

this.customerBindingSource.DataSource = this.costumer;

where this.contumer is created and instialized instance of the Costumer
class.

BTW if you want the datagridview to reflect the changes made to the
properties of the business at run-time (after the grid is bound) your
business object needs to implement INotifyPropertyChanged interface and fire
the event anytime a property changes
 
S

Steve

Very good information, thank you for taking the time to explain this! I'm
up and running now.
Have a good day,
Steve
 

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