Data binding to an object

S

Simon Verona

I don't know if I'm missing something... but.. is it possible to databind a
text box to a read/write property of an object at design time?

I see lots of examples to binding to a dataadapter etc, but if I have a
class which represents a business object can I bind directly to the
properties of the class?

Regards
Simon

--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011
 
S

Steven Nagy

Yes but only in VS2005. Older versions I don't think its possible...
There's new object data providers in 2005 although I haven't actually
started using 2005 yet so not sure how, where, etc.
 
S

Simon Verona

Ok thanks.. I'm still on VS2003.. It seems like an interesting omission.

As an aside, if I was to try and implement this by inheriting the textbox
class (and perhaps some of the others) and have two additional properties
called "object name" and "property name", could I then access the property
through reflection?

Would there be a performance penalty to pay to do this?

Anybody give me a head start in terms of coding... ?

Thanks in advance
Simon
--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011
 
S

Steven Nagy

That would work. I wouldn't be able to comment on the performance of
reflection. I use it but have never clocked it. Wouldn't be too bad I
suppose because you aren't talking about massive amounts of objects and
form components right? Check out the System.Type class and all its
methods for getting lists of fields and methods and so on to get
started with reflection.

But there might be an easier way.

Perhaps you only need your object to implement an interface to
databind. I haven't investigated this specifically, but what is the
distinct attributes of the data table and data row that allow them to
be data bound?
Could your object inherit from these instead? Or is changing the object
not possible?

I assume you have checked out the BindingManager and all its uses?

Steven
 
S

Simon Verona

Don't assume anything!! ;)

I've not checked out anything yet.

I'm looking for the longer term... At the moment, some of my business logic
is exposed in my user interface, mainly because because I need to bind to
the raw data.

I want to be able to remove all the business logic into a seperate set of
classes, and then bind to the various properties instead - this will allow
me to neaten my code up and remove lots of the business logic out of my UI
(I've already done some of this by writing classes that partially handle the
logic).

I'm planning to migrate to VS2005 towards the end of the year, so I may just
wait till then before I do this.

Regards
Simon

--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011
 

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