DataBinding to class objects

Joined
Jan 17, 2008
Messages
8
Programming Experience
10+
I've split my solution into business layer (class objects), data layer (SQL specific), and UI layer (forms and user controls). I can add a datasource for my class objects within the main project but I can't do the same at my UI level where I need it.

I have an openning form in my main project which I can drag and drop the datasource objects to the form with no problem. However, I need this functionality in my UI form objects which are contained in a seperate project (.dll) which I reference in my main project.

When I try to add a datasource at my UI level I get the following problem: I select Object as my datasource and then select next. I get the following error: An unexpected error has occurred - Error Message: Object reference not set to and instance of an object.

Any ideas?
 
You can't use the designer to bind business objects. You need to do it in code. Your DAL retrieves the data and pass it to your BLL in a DataTable. Your BLL creates a business object for each row in the table, adds then all to a collection and passes that to your PL. Your PL then binds that collection to the controls, e.g.
VB.NET:
Me.BindingSource1.DataSource = Me.businessLogicManager.GetWidgets()
Me.DataGridView1.DataSource = Me.BindingSource1
businessLogicManager is a class in your BLL that manages your business rules. GetWidgets is a method that gets a DataTable full of Widget records from the DAL, packages that data into a collection of Widget objects and returns it. That way you get your DataGridView bound to a collection of Widget objects, which is what you want.
 
Back
Top