Problem updating object behind bindingSource

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

Hi folks,

I have an form where there are two text boxes bound to an object via a
BindingSource. I have implemented a document save function via Binary
Serialization that writes the underlying object to disk.

The problem is, if a user edits the data in one of the text boxes but
DOES NOT leave the text box before selecting the Save menu item, the
change in the text box is not replicated back to the object behind the
form (the object that is serialized). Hence when I reload the document
the Deserialized data contains the contents of the textbox before the
user changed it. If the user leaves the textbox first, everything is fine.

My thinking is that I need to force the form to propagate its current
state back to the object before serializing, but would take some advice
on the best way to do this.

I appreciate this is not strictly an ADO.NET question but figured that
being a data binding issue, someone on here might be able to help.

Many thanks in advance.

Simon
 
Hi,

Simon said:
Hi folks,

I have an form where there are two text boxes bound to an object via a
BindingSource. I have implemented a document save function via Binary
Serialization that writes the underlying object to disk.

The problem is, if a user edits the data in one of the text boxes but DOES
NOT leave the text box before selecting the Save menu item, the change in
the text box is not replicated back to the object behind the form (the
object that is serialized). Hence when I reload the document the
Deserialized data contains the contents of the textbox before the user
changed it. If the user leaves the textbox first, everything is fine.

My thinking is that I need to force the form to propagate its current
state back to the object before serializing, but would take some advice on
the best way to do this.

Call BindingSource.EndEdit() before you serialize the object.

hth,
Greetings
 
Actually Bart, this hasn't solved it.

It seems to have to do with the textbox still having the focus. Seems
the underlying datasource is not updated until the textbox loses focus.
Calling BindingSource.EndEdit() hasn't made any difference if I don't
leave the textbox before select Save from the menu.

I'm thinking that I need to code in "losing the focus" but just wondered
if there is a more elegant way of doing this.

Cheers

Simoin
 
Sorry scratch that .. I'm an idiot. Was a mistake in my logic. Works
just fine.

Thanks again

Simon
 
Back
Top