in my Winform Project, i have a simple detail form where we can add new, edit and save persistent Object, until here everything is fine.
Edit Controls are binded by code in the from constructor, and the first new object is also passed by the form constructor when created at first time
Now i would like to implement a Save and New method, but without success
I tried this, assuming that tbVehicule is the object class, theVehicule is my persistent Object and frmVehicule my detail form
// Form Constructor
public frmVehicule(tbVehicule theVehicule)
: this() {
this.theVehicule = theVehicule;
// method to bind all controls
bindingFields();
}
// Save and new method
private void barBtnSaveNew_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
this.Validate();
theVehicule.Save();
theVehicule = new tbVehicule(theVehicule.Session);
}
the process should be similar to other ORM like EF or Hibernate
I solved the problem by myself, so I answered my question hope it will help someone, it does not work, because the DataBinding mechanism only works in one direction (form Controls to Object)
if we instantiate new object in our binded object, the controls values don't follows (they are not updated), for this we need to reset a bindings
with above snipet it's work fine,may be that there are a more elegant way to reset a binding, I opted for redefining bindings, because it is the only one method that I found and that works for the moment. .