473,394 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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:

textBoxStartDate.DataBindings.Add("Text", CurrentStep,
"StartDate",
true, DataSourceUpdateMode.OnValidation, 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 2572
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 INotifyPropertyChanged interface, and
invoke the PropertyChanged event in every setter. As an example (taken
indirectly from WSDL.exe output):

public class MyObj : object,
System.ComponentModel.INotifyPropertyChanged{
[System.Xml.Serialization.XmlElementAttribute(IsNul lable=true)]
public System.Nullable<System.DateTime> ImplementationActual {
get {
return this.implementationActualField;
}
set {
if ((this.implementationActualField != value)) {
this.implementationActualField = value;
this.RaisePropertyChanged("ImplementationActual");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler
PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler
propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new
System.ComponentModel.PropertyChangedEventArgs(pro pertyName));
}
}
}
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 implementationActual is a
date-picker):

this.implementationActual.DataBindings.Add(new
System.Windows.Forms.Binding("Value", bindingSource, "ImplementationActual",
true));

3: add the object to the BindingSource:

List<MyObj> data = new List<MyObj>();
data.Add(item);
bindingSource.DataSource = 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**************@TK2MSFTNGP14.phx.gbl...
Hi-- I'm trying to databind a business object to several controls using
the DataBindings property of the controls, like this:

textBoxStartDate.DataBindings.Add("Text", CurrentStep,
"StartDate",
true, DataSourceUpdateMode.OnValidation, 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
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...
2
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...
3
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...
2
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...
1
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; }...
5
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...
1
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...
8
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...
7
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...
3
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:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.