473,804 Members | 3,349 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 2588
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
3685
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
1244
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 named ObjectName. In the code behind, I can use this fine, but the following will cause the error I...
3
1864
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 on 2.0, and I find this automatic functionality doesn't do much beyond allowing me to generate...
2
3767
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
2147
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
3485
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
18893
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 reflected in the DataGridView (in other words I was expecting the 2 way databinding to actually...
8
2092
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
2598
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 happen until user click update button.
3
1404
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 the inserted data? Should the validation logic be handled by the UI or the underlying business...
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10567
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10310
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.