Databindable hierarchical object

G

Guest

Hi all - I was wondering what would be the best way to implement a
hierarchical structure so that I can use it in databinding.

Here's my situation: We are building a windows form app, and we are not
using DataSets. I have various business entities, and custom collections
(and these collections are bindable).

What I would like to do is to create a hierarchy of these business entities.
I'd like to keep the hierarchical relationships separate from the entities
themselves. My ideal object will be a Generic, and each instance will
contain only a single entity type. I would like to retrieve the entities and
their relations from the database, and then pass them to the UI which will
then databind to it. We're using Infragistics controls, if it matters.

I'm curious as to what interfaces I need to implement to ensure that I can
databind in a way that will allow the UI to view the hierarchy of entities
w/o having to actually parse the tree and insert the appropriate nodes. I've
yet to see an example. Can anyone point me in the right direction?

Thanks!
Phil
 
D

Dave Sexton

Hi Phil,
Here's my situation: We are building a windows form app, and we are not
using DataSets. I have various business entities, and custom collections

What is it about the DataSet class that doesn't meet the needs of your app?
Business objects should contain business logic routines and provide
intuitive interfaces for other components and DataSets can be used to manage
the underlying business data. Without DataSets you lose out on so much.
What I would like to do is to create a hierarchy of these business
entities.
I'd like to keep the hierarchical relationships separate from the entities
themselves. My ideal object will be a Generic, and each instance will
contain only a single entity type. I would like to retrieve the entities
and
their relations from the database, and then pass them to the UI which will
then databind to it

Strong-Typed DataSets do all of this out-of-the-box and more. I suggest
thoroughly researching DataSets before attempting to recreate their
functionality in custom code.
I'm curious as to what interfaces I need to implement to ensure that I can
databind in a way that will allow the UI to view the hierarchy of entities
w/o having to actually parse the tree and insert the appropriate nodes.
I've
yet to see an example. Can anyone point me in the right direction?

In .NET 2.0 use the BindingSource class to wrap your business object and
bind controls to the BindingSource class. BindingSource will allow controls
to bind to the public properties of your object. Using BindingSource hides
the complexities in implementing IBindingList, an interface that an object
exposes when it supplies an IList for binding. In previous framework
versions you'll need to implement ICollection on your collections or
IBindingList for a more complex binding architecture.

HTH
 
G

Grant Frisken

If you don't want to use DataSets you don't have to give up data
binding but you do, as Dave, pointed out have to implement certain
interfaces on your collections (in particular IBindingList) to take
full advantage of two way data binding (where the data source notifies
client controls when it is changed allowing the controls to update
automatically).

Most tree/grid controls don't handle binding to arbitrary hierarchical
data sources. You might want to take a look at Infralutions Virtual
Tree control which is designed for this type of scenario

Regards
Grant Frisken
Infralution
www.infralution.com
 
G

Guest

Thanks to both of you who replied. I'm not completely finished, but I have a
good start.
I can't switch to datasets now - we're too far along in the course of our
project. However, using Generics, I came up with the start of a workable
solution.

I haven't implemented IBindingList yet, but I did implement ITypedList. I
also used Generics to create a PropertyDescriptor that's basically a wrapper
for the actual PropertyDescriptor of the contained entity. This works pretty
well.

Thanks,
Phil
 

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