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