473,545 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databinding to business object

Hi-- I'm trying to databind a business object to several controls using the
DataBindings property of the controls, like this:

textBoxStartDat e.DataBindings. Add("Text", CurrentStep,
"StartDate" ,
true, DataSourceUpdat eMode.OnValidat ion, String.Empty,
"d");

Where CurrentStep is a business object of type ProjectStep, with several
properties, such as the StartDate property shown above.

When the form initializes, and a ProjectStep object is plugged into
CurrentStep, the controls update their values as expected. But if
currentStep is set to another ProjectStep object after that, the controls
don't update. They retain the values from the first ProjectStep object
passed in.

What do I need to do to make the controls update when the CurrentStep object
is updated? Is there a call I need to make when the call is updated? Thanks
in advance for your help.

David Veeneman
Foresight Systems
Nov 30 '05 #1
1 2579
If you are changing the actual object (i.e. a new object), then your
approach won't work (short of manually resetting all of your bindings). If
you are simply updating values on the *existing* object (using setters),
then your object should implement the INotifyProperty Changed interface, and
invoke the PropertyChanged event in every setter. As an example (taken
indirectly from WSDL.exe output):

public class MyObj : object,
System.Componen tModel.INotifyP ropertyChanged{
[System.Xml.Seri alization.XmlEl ementAttribute( IsNullable=true )]
public System.Nullable <System.DateTim e> ImplementationA ctual {
get {
return this.implementa tionActualField ;
}
set {
if ((this.implemen tationActualFie ld != value)) {
this.implementa tionActualField = value;
this.RaisePrope rtyChanged("Imp lementationActu al");
}
}
}
public event System.Componen tModel.Property ChangedEventHan dler
PropertyChanged ;
protected void RaisePropertyCh anged(string propertyName) {
System.Componen tModel.Property ChangedEventHan dler
propertyChanged = this.PropertyCh anged;
if ((propertyChang ed != null)) {
propertyChanged (this, new
System.Componen tModel.Property ChangedEventArg s(propertyName) );
}
}
}
The reason the former doesn't work is that your controls are still quite
happily bound to the existing object; the way to do this is to not bind
directly to the object, but to a BindingSource, e.g.

1: place a binding source onto your form (as a component) and link it to the
right data type
2: setup your bindings (example below where implementationA ctual is a
date-picker):

this.implementa tionActual.Data Bindings.Add(ne w
System.Windows. Forms.Binding(" Value", bindingSource, "Implementation Actual",
true));

3: add the object to the BindingSource:

List<MyObj> data = new List<MyObj>();
data.Add(item);
bindingSource.D ataSource = data;

Now when you change the object in the data source (either by resetting the
list to a new instance, or by removing, adding, etc to the data-source and
moving to the correct record) your bindings update themselves correctly.

Does this help?

Marc

"David Veeneman" <da****@nospam. com> wrote in message
news:uP******** ******@TK2MSFTN GP14.phx.gbl...
Hi-- I'm trying to databind a business object to several controls using
the DataBindings property of the controls, like this:

textBoxStartDat e.DataBindings. Add("Text", CurrentStep,
"StartDate" ,
true, DataSourceUpdat eMode.OnValidat ion, String.Empty,
"d");

Where CurrentStep is a business object of type ProjectStep, with several
properties, such as the StartDate property shown above.

When the form initializes, and a ProjectStep object is plugged into
CurrentStep, the controls update their values as expected. But if
currentStep is set to another ProjectStep object after that, the controls
don't update. They retain the values from the first ProjectStep object
passed in.

What do I need to do to make the controls update when the CurrentStep
object is updated? Is there a call I need to make when the call is
updated? Thanks in advance for your help.

David Veeneman
Foresight Systems

Dec 1 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3666
by: Tim Jarvis | last post by:
Hi, I have an object that I am binding to a text box, this object exposes a boolean field, and I have implemented a format event handler and a parse event handler for the binding object, where I convert the bool value to some meaningful text. i.e. Binding b = new
2
1233
by: Steven | last post by:
Hi, I'm having an odd problem with late databinding (using DataBinder.Eval). I have my Business Logic and Facade assemblies in the GAC, and just about everything works fine, however, when using pages which use the DataBinder.Eval method, I get an error saying the referenced assembly could not be found. For example, say I have an object...
3
1846
by: John Bailey | last post by:
When I first built a few web pages in ASP .Net 2.0, I thought it was great. The formview and detailview contorls would automatically layout the controls for you, the update methods were automatically generated, and the objectdatasource let you design against a business object through the gui. Now I am working on my first real web application...
2
3757
by: ulrich schumacher | last post by:
Hi ASP.NET 2.0 Professionals, I've got a question concerning the new ASP.NET 2.0 DataBinding with object oriented business classes: Example: There are two business classes in my domain model: public class Language
1
2136
by: thzero | last post by:
Is there any way to do this without using the ObjectDataSource? (Apologies for the long post) I have a simple data object: public class TestDO { public TestDO() {} public ID { get; set; } public Name { get; set; } public Description { get; set; }
5
3465
by: Trail Monster | last post by:
Ok, I've been searching the net now for several days and can't find how to do this anywhere. Version: VS 2005 Professional Release, 2.0 Framework Background: I have a complex business object Employee that contains public properties and several nested objects such as a Spouse object and a List of Coverage objects.
1
18798
by: Dave A | last post by:
Hi, I am struggling with two way databinding in WinForms and the DataGridView. I am binding to business object classes (rather than datatables). If I have a collection of these business objects that is the datasource of a DataBinding that is bound to a DataGridView (WinForms) then I was expecting that any change to the data would be...
8
2077
by: Dirk | last post by:
Hello, I have a problem to use databinding with my business layer classes. My data class does not have simple properties (string, int or datetime), instead, all my properties are objects of the generic type Field<T> (see sample code). public class Employee { public Field<stringForename
7
2583
by: Vlado Jasovic | last post by:
Hello, I'm using typed dataset for databinding to windows controls and I'm having some problems. I'm trying to move all business logic to datatable column_changing events and the problem that I'm having is when I change some other column, control value doesn't update immediately until I call endcurrentedit on bindingmanager which doesnt...
3
1396
by: nagar | last post by:
I was thinking about using databinding to display the user settings. I'm not using the .NET 2.0 ApplicationSettings but I'm using a class that contains all the settings. I have a few questions: 1. What's the best practice to store settings? I like using my own class as I can choose how to serialize and store the data 2. How do I validate...
0
7420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7934
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6003
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5349
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.